Dynamic import (#5169)

* dynamic import

* updated grammar

* specify callable

* DynamicImportCall

* Fix from code review

Co-Authored-By: helixbass <julian@helixbass.net>

* recompile
This commit is contained in:
Julian Rosse
2019-03-20 16:08:10 -04:00
committed by Geoffrey Booth
parent ca275c2a1c
commit ff24e5ce52
10 changed files with 302 additions and 196 deletions

View File

@@ -1925,3 +1925,29 @@ test "`new.target` is only allowed meta property", ->
-> new.something
^^^^^^^^^^^^^
'''
test "#4834: dynamic import requires exactly one argument", ->
assertErrorFormat '''
import()
''', '''
[stdin]:1:1: error: import() requires exactly one argument
import()
^^^^^^^^
'''
assertErrorFormat '''
import('x', {})
''', '''
[stdin]:1:1: error: import() requires exactly one argument
import('x', {})
^^^^^^^^^^^^^^^
'''
test "#4834: dynamic import requires explicit call parentheses", ->
assertErrorFormat '''
promise = import 'foo'
''', '''
[stdin]:1:23: error: unexpected end of input
promise = import 'foo'
^
'''

View File

@@ -920,3 +920,24 @@ test "#4874: backslash `export`", ->
min
} from 'underscore';
"""
test "#4834: dynamic import", ->
eqJS """
import('module').then ->
""",
"""
import('module').then(function() {});
"""
eqJS """
foo = ->
bar = await import('bar')
""",
"""
var foo;
foo = async function() {
var bar;
return bar = (await import('bar'));
};
"""

View File

@@ -418,3 +418,13 @@ test "#4673: complex destructured object spread variables", ->
g = ({@y...}) ->
eq @y.b, 1
g b: 1
test "#4834: dynamic import can technically be object spread", ->
eqJS """
x = {...import('module')}
""",
"""
var x;
x = {...import('module')};
"""