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

Be much more careful about parsing * in import and export statements #4308

Merged
merged 1 commit into from
Sep 15, 2016

Conversation

GeoffreyBooth
Copy link
Collaborator

While writing the documentation for modules, I stumbled across a bug. Yes, I broke it already.

I was writing this as an example:

export square = (x) -> x * x

Which choked on the *, because our check for whether * should be treated as EXPORT_ALL was whether we’ve seen an EXPORT token and that the indent was 0. I knew that indent check was going to be trouble; but I gave it a lot more thought this time, and noticed two things:

  • In import statements, an * always precedes an as.
  • In export statements, the only time * can appear is in a statement like export * from 'lib'

So I made the check for converting * to IMPORT_ALL or EXPORT_ALL much narrower, based on these two rules. This made my example compile properly, and broke no other tests. I added two new tests like this example, where * is used on the same line (and indentation level) as an export keyword. I also re-ran the Meteor todos test.

@lydell you were wondering why we can’t just put * in the grammar? It’s because the lexer converts * to tag MATH, and I don’t want to write grammar like EXPORT MATH FROM String. That doesn’t make much sense, and then in ExportAllDeclaration I would need to filter whether MATH was an * and throw an error otherwise. Better to intercept * in the lexer and convert it to IMPORT_ALL or EXPORT_ALL there rather than MATH.

…s; handle export expressions that use `*` on the same line as `export`
@lydell lydell merged commit 7667cb2 into jashkenas:master Sep 15, 2016
@lydell
Copy link
Collaborator

lydell commented Sep 15, 2016

Nice catch!

@GeoffreyBooth GeoffreyBooth deleted the import-export branch September 17, 2016 17:23
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.

2 participants