Allow keywords in named import/export syntax #107
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Progress toward #98
See the imports and exports grammar from the spec:
https://www.ecma-international.org/ecma-262/8.0/index.html#sec-imports
https://www.ecma-international.org/ecma-262/8.0/index.html#sec-exports
In particular, ImportSpecifier and ExportSpecifier use IdentifierName to
identify the import/export name rather than the more restrictive ImportedBinding
(or just Identifier). That means any keyword is allowed.
There are (at least) three contexts to think about in JS identifier parsing:
reserved word.
keyword-like meaning in specific situations. Acorn and Babel call these
"contextual keywords", and
tokenIsAlsoIdentifier
andpreferIdentifier
inAssemblyScript appear to handle that case.
allowed, even keywords.
This change adds that third case in order to handle imports/exports. I added a
forceIdentifier
flag that tells the tokenizer that any identifier name shouldbe treated as a plain identifier, then used it in the import and export cases.