mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
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:
committed by
Geoffrey Booth
parent
ca275c2a1c
commit
ff24e5ce52
@@ -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'
|
||||
^
|
||||
'''
|
||||
|
||||
@@ -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'));
|
||||
};
|
||||
"""
|
||||
|
||||
@@ -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')};
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user