Skip to content

Commit 2a5378c

Browse files
committed
fix: for commonjs, set Program.sourceType to script
1 parent a0421c0 commit 2a5378c

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

acorn-loose/src/statement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ lp.parseTopLevel = function() {
1010
while (this.tok.type !== tt.eof) node.body.push(this.parseStatement())
1111
this.toks.adaptDirectivePrologue(node.body)
1212
this.last = this.tok
13-
node.sourceType = this.options.sourceType
13+
node.sourceType = this.options.sourceType === "commonjs" ? "script" : this.options.sourceType
1414
return this.finishNode(node, "Program")
1515
}
1616

acorn/src/acorn.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface Literal extends Node {
3838
export interface Program extends Node {
3939
type: "Program"
4040
body: Array<Statement | ModuleDeclaration>
41-
sourceType: "script" | "module" | "commonjs"
41+
sourceType: "script" | "module"
4242
}
4343

4444
export interface Function extends Node {

acorn/src/statement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pp.parseTopLevel = function(node) {
2727
this.raiseRecoverable(this.undefinedExports[name].start, `Export '${name}' is not defined`)
2828
this.adaptDirectivePrologue(node.body)
2929
this.next()
30-
node.sourceType = this.options.sourceType
30+
node.sourceType = this.options.sourceType === "commonjs" ? "script" : this.options.sourceType
3131
return this.finishNode(node, "Program")
3232
}
3333

test/tests-commonjs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test("using x = resource;", {
2121
}],
2222
kind: "using"
2323
}],
24-
sourceType: "commonjs"
24+
sourceType: "script"
2525
}, {ecmaVersion: 17, sourceType: "commonjs"});
2626

2727
// Top-level new.target with commonjs
@@ -35,7 +35,7 @@ test("new.target", {
3535
property: {type: "Identifier", name: "target"}
3636
}
3737
}],
38-
sourceType: "commonjs"
38+
sourceType: "script"
3939
}, {ecmaVersion: 6, sourceType: "commonjs"});
4040

4141
// new.target at top-level scope with commonjs
@@ -61,7 +61,7 @@ test("let y = () => new.target", {
6161
}],
6262
kind: "let"
6363
}],
64-
sourceType: "commonjs"
64+
sourceType: "script"
6565
}, {ecmaVersion: 6, sourceType: "commonjs"});
6666

6767
// Top-level return statement with commonjs
@@ -82,7 +82,7 @@ test("return {} / 2", {
8282
operator: "/"
8383
}
8484
}],
85-
sourceType: "commonjs"
85+
sourceType: "script"
8686
}, {sourceType: "commonjs"});
8787

8888
// Illegal return statement with commonjs

0 commit comments

Comments
 (0)