Skip to content
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

helixbass
Copy link
Collaborator

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 lexes as, 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 a lineToken() clears @seenImport and @seenExport

Not sure if I should add additional tests for any of the other various import/export syntaxes?

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? ...
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

@helixbass
Copy link
Collaborator Author

@GeoffreyBooth ok put imports first

Also updated previously merged (via #4490) fix for #4489 to follow style guide and use camelCase

@GeoffreyBooth
Copy link
Collaborator

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 '}'
Copy link
Collaborator

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator

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'
    |             ^

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks, TIL!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants