Skip to content

Commit 07f644c

Browse files
Fix call MetaProperty (#5324)
1 parent 2fd9ee4 commit 07f644c

File tree

6 files changed

+30
-9
lines changed

6 files changed

+30
-9
lines changed

lib/coffeescript/grammar.js

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript/rewriter.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/grammar.coffee

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ grammar =
113113
o 'Body TERMINATOR'
114114
]
115115

116-
# Block and statements, which make up a line in a body. YieldReturn is a
116+
# Block and statements, which make up a line in a body. FuncDirective is a
117117
# statement, but not included in Statement because that results in an ambiguous
118118
# grammar.
119119
Line: [
@@ -325,7 +325,7 @@ grammar =
325325
o 'AWAIT RETURN', -> new AwaitReturn null, returnKeyword: LOC(2)(new Literal $2)
326326
]
327327

328-
# The **Code** node is the function literal. It's defined by an indented block
328+
# The **Code** node is the function literal. Its defined by an indented block
329329
# of **Block** preceded by a function arrow, with an optional parameter list.
330330
Code: [
331331
o 'PARAM_START ParamList PARAM_END FuncGlyph Block', -> new Code $2, $5, $4, LOC(1)(new Literal $1)
@@ -421,7 +421,8 @@ grammar =
421421
o 'SUPER INDEX_START INDENT Expression OUTDENT INDEX_END', -> new Super LOC(4)(new Index $4), LOC(1)(new Literal $1)
422422
]
423423

424-
# A "meta-property" access e.g. `new.target`
424+
# A “meta-property” access e.g. `new.target` or `import.meta`, where
425+
# something that looks like a property is referenced on a keyword.
425426
MetaProperty: [
426427
o 'NEW_TARGET . Property', -> new MetaProperty LOC(1)(new IdentifierLiteral $1), LOC(3)(new Access $3)
427428
o 'IMPORT_META . Property', -> new MetaProperty LOC(1)(new IdentifierLiteral $1), LOC(3)(new Access $3)
@@ -774,7 +775,7 @@ grammar =
774775
]
775776

776777
# The source of a comprehension is an array or object with an optional guard
777-
# clause. If it's an array comprehension, you can also choose to step through
778+
# clause. If its an array comprehension, you can also choose to step through
778779
# in fixed-size increments.
779780
ForSource: [
780781
o 'FORIN Expression', -> source: $2

src/rewriter.coffee

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ IMPLICIT_CALL = [
814814
'IDENTIFIER', 'JSX_TAG', 'PROPERTY', 'NUMBER', 'INFINITY', 'NAN'
815815
'STRING', 'STRING_START', 'REGEX', 'REGEX_START', 'JS'
816816
'NEW', 'PARAM_START', 'CLASS', 'IF', 'TRY', 'SWITCH', 'THIS'
817+
'DYNAMIC_IMPORT', 'IMPORT_META', 'NEW_TARGET'
817818
'UNDEFINED', 'NULL', 'BOOL'
818819
'UNARY', 'DO', 'DO_IIFE', 'YIELD', 'AWAIT', 'UNARY_MATH', 'SUPER', 'THROW'
819820
'@', '->', '=>', '[', '(', '{', '--', '++'

test/classes.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,10 @@ test "#4609: Support new.target", ->
19171917
new Foo()
19181918
eq newTarget, yes
19191919

1920+
test "#5323: new.target can be the argument of a function", ->
1921+
fn = (arg) -> arg
1922+
fn new.target
1923+
19201924
test "#5085: Bug: @ reference to class not maintained in do block", ->
19211925
thisFoo = 'initial foo'
19221926
thisBar = 'initial bar'

test/modules.coffee

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,13 @@ test "#4834: dynamic import", ->
942942
};
943943
"""
944944

945+
eqJS """
946+
console.log import('foo')
947+
""",
948+
"""
949+
console.log(import('foo'));
950+
"""
951+
945952
test "#5317: Support import.meta", ->
946953
eqJS """
947954
foo = import.meta
@@ -991,3 +998,10 @@ test "#5317: Support import.meta", ->
991998
992999
foo = import.meta.bar;
9931000
"""
1001+
1002+
eqJS """
1003+
console.log import.meta.url
1004+
""",
1005+
"""
1006+
console.log(import.meta.url);
1007+
"""

0 commit comments

Comments
 (0)