Skip to content

Commit 25c2378

Browse files
helixbassGeoffreyBooth
authored andcommitted
AST: recognize quoted constructor (#5251)
* astNode() * no override ast() * add suggested comments * astInitialize() * astAddReturns() * separate step * recognize quoted constructor
1 parent 47bf5d9 commit 25c2378

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

lib/coffeescript/nodes.js

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

src/nodes.coffee

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2900,7 +2900,12 @@ exports.Class = class Class extends Base
29002900
methodName = variable.base
29012901
method.name = new (if methodName.shouldCache() then Index else Access) methodName
29022902
method.name.updateLocationDataIfMissing methodName.locationData
2903-
method.ctor = (if @parent then 'derived' else 'base') if methodName.value is 'constructor'
2903+
isConstructor =
2904+
if methodName instanceof StringLiteral
2905+
methodName.originalValue is 'constructor'
2906+
else
2907+
methodName.value is 'constructor'
2908+
method.ctor = (if @parent then 'derived' else 'base') if isConstructor
29042909
method.error 'Cannot define a constructor as a bound (fat arrow) function' if method.bound and method.ctor
29052910

29062911
method.operatorToken = operatorToken

test/abstract_syntax_tree.coffee

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,29 @@ test "AST as expected for Class node", ->
18721872
object: ID 'A', declaration: no
18731873
property: ID 'b', declaration: no
18741874

1875+
testStatement '''
1876+
class A
1877+
'constructor': ->
1878+
''',
1879+
type: 'ClassDeclaration'
1880+
body:
1881+
type: 'ClassBody'
1882+
body: [
1883+
type: 'ClassMethod'
1884+
static: no
1885+
key:
1886+
type: 'StringLiteral'
1887+
computed: no
1888+
kind: 'constructor'
1889+
id: null
1890+
generator: no
1891+
async: no
1892+
params: []
1893+
body: EMPTY_BLOCK
1894+
bound: no
1895+
]
1896+
1897+
18751898
test "AST as expected for ModuleDeclaration node", ->
18761899
testStatement 'export {X}',
18771900
type: 'ExportNamedDeclaration'

0 commit comments

Comments
 (0)