diff --git a/packages/keyword-fn/fixture/fn-function.gs b/packages/keyword-fn/fixture/fn-function.gs new file mode 100644 index 0000000..581311d --- /dev/null +++ b/packages/keyword-fn/fixture/fn-function.gs @@ -0,0 +1 @@ +function fn() {} diff --git a/packages/keyword-fn/index.js b/packages/keyword-fn/index.js index 95ec05a..cb2cf16 100644 --- a/packages/keyword-fn/index.js +++ b/packages/keyword-fn/index.js @@ -1,4 +1,5 @@ import {addKeyword, TokenType} from '../operator/index.js'; +import {tokTypes as tt} from 'acorn'; export default function fn(Parser) { Parser.acorn.keywordTypes.fn = new TokenType('fn', { @@ -13,7 +14,9 @@ export default function fn(Parser) { } parseStatement(context, topLevel, exports) { - if (this.type === Parser.acorn.keywordTypes.fn) + const isParen = this.eat(tt.parenL); + + if (!isParen && this.type === Parser.acorn.keywordTypes.fn) this.type = Parser.acorn.keywordTypes.function; return super.parseStatement(context, topLevel, exports); @@ -25,5 +28,15 @@ export default function fn(Parser) { return super.shouldParseExportStatement(); } + + checkUnreserved(ref) { + const {name} = ref; + + if (name === 'fn') + return; + + return super.checkUnreserved(ref); + } }; } + diff --git a/packages/keyword-fn/index.spec.js b/packages/keyword-fn/index.spec.js index 69817e1..7b4209e 100644 --- a/packages/keyword-fn/index.spec.js +++ b/packages/keyword-fn/index.spec.js @@ -8,6 +8,11 @@ test('goldstein: keyword: fn', (t) => { t.end(); }); +test('goldstein: keyword: fn-function', (t) => { + t.noCompile('fn-function'); + t.end(); +}); + test('goldstein: keyword: fn: export', (t) => { t.compile('export'); t.end();