-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix #4491: import- and export-specific lexing should stop #4492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #4491: import- and export-specific lexing should stop #4492
Conversation
src/lexer.coffee
Outdated
@@ -46,6 +46,7 @@ exports.Lexer = class Lexer | |||
@seenImport = no # Used to recognize IMPORT FROM? AS? tokens. | |||
@seenExport = no # Used to recognize EXPORT FROM? AS? tokens. | |||
@exportSpecifierList = no # Used to identify when in an EXPORT {...} FROM? ... | |||
@importSpecifierList = no # Used to identify when in an IMPORT {...} FROM? ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep it consistent and always put the import stuff before the export stuff.
src/lexer.coffee
Outdated
@@ -477,6 +480,10 @@ exports.Lexer = class Lexer | |||
@exportSpecifierList = yes | |||
else if @exportSpecifierList and value is '}' | |||
@exportSpecifierList = no | |||
else if value is '{' and @seenImport |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
@GeoffreyBooth ok put imports first Also updated previously merged (via #4490) fix for #4489 to follow style guide and use camelCase |
Thanks. Looks good to me, @lydell? |
if value is '{' and prev?[0] is 'EXPORT' | ||
if value is '{' and @seenImport | ||
@importSpecifierList = yes | ||
else if @importSpecifierList and value is '}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't handle nested objects, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vendethiel right, I didn't see any cases in the documentation or tests where an import
could contain nested-object syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vendethiel the “destructuring” in ES2015 import
statements is just a similar-looking syntax:
import { a: b } from 'lib'
repl: ES2015 named imports do not destructure. Use another statement for destructuring after the import. (1:12)
> 1 | import { a: b } from 'lib'
| ^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thanks, TIL!
Fixes #4491 (I think)
I'm not really familiar with the
import
/export
syntax but it looks like the only the time that the import-/export-specific lexing controlled by@seenImport
/@seenExport
(which lexesas
,from
,default
differently) needs to continue beyond a line break is if we're inside a{...}
specifier list. So I added an@importSpecifierList
(corresponding to the existing@exportSpecifierList
), and unless one of these is set (indicating we're inside a specifier list) then seeing alineToken()
clears@seenImport
and@seenExport
Not sure if I should add additional tests for any of the other various
import
/export
syntaxes?