-
Notifications
You must be signed in to change notification settings - Fork 0
Add support for simple import *statement* to identifier #2
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
Changes from 1 commit
21de343
118c11c
d2e6481
d86540a
de78f48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -258,6 +258,13 @@ exports.Lexer = class Lexer | |
@token 'JS', (script = match[0])[1...-1], 0, script.length | ||
script.length | ||
|
||
importToken: -> | ||
match = @chunk.match(IMPORT) | ||
|
||
return 0 unless match | ||
|
||
@token('IMPORT', match[0], 0, match[0].length) | ||
|
||
# Matches regular expression literals, as well as multiline extended ones. | ||
# Lexing regular expressions is difficult to distinguish from division, so we | ||
# borrow some basic heuristics from JavaScript and Ruby. | ||
|
@@ -774,7 +781,7 @@ JS_KEYWORDS = [ | |
'return', 'throw', 'break', 'continue', 'debugger', 'yield' | ||
'if', 'else', 'switch', 'for', 'while', 'do', 'try', 'catch', 'finally' | ||
'class', 'extends', 'super' | ||
'export', 'import', 'default' | ||
'export', 'import', 'from', 'default' | ||
] | ||
|
||
# CoffeeScript-only keywords. | ||
|
@@ -849,6 +856,8 @@ MULTI_DENT = /^(?:\n[^\n\S]*)+/ | |
|
||
JSTOKEN = /^`[^\\`]*(?:\\.[^\\`]*)*`/ | ||
|
||
IMPORT = /^import .+/ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the way to go. Have a look at how other keywords, such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After looking at the changes, it's not used anyways.. 🐹 |
||
# String-matching-regexes. | ||
STRING_START = /^(?:'''|"""|'|")/ | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,15 +21,15 @@ test "import module", -> | |
# console.log toJS input | ||
eq toJS(input), output | ||
|
||
# test "module import test, syntax #1", -> | ||
# input = "import foo from 'lib'" | ||
# output = "import foo from 'lib';" | ||
# eq toJS(input), output | ||
test "module import test, syntax #1", -> | ||
input = "import foo from 'lib'" | ||
output = "import foo from 'lib';" | ||
eq toJS(input), output | ||
|
||
# test "module import test, syntax #2", -> | ||
# input = "import { foo } from 'lib'" | ||
# output = "import { foo } from 'lib';" | ||
# eq toJS(input), output | ||
test "module import test, syntax #2", -> | ||
input = "import { foo } from 'lib'" | ||
output = "import { foo } from 'lib';" | ||
eq toJS(input), output | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also remember to add tests for invalid stuff (in test/error_messages.coffee). |
||
|
||
# test "module import test, syntax #3", -> | ||
# input = "import { default as foo } 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.
You need to replace
Assignable
with something new that represents the ES2015 import syntax, andExpression
with something that only matches'
and"
strings (also keep in mind that interpolation cannot be used here.)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.
I thought this was a destructured assignment, just like CS already supports (syntactically). Is it not?