Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: parser
strictMode
option (#13548)
- Loading branch information
1 parent
2c6db56
commit dd942f9
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { parse } from "../lib"; | ||
|
||
describe("options", () => { | ||
describe("strictMode", () => { | ||
const CODE = "function f(x, x) {}"; | ||
|
||
function expectToSucceed(opts) { | ||
expect(parse(CODE, opts).program.body[0]).toMatchObject({ | ||
type: "FunctionDeclaration", | ||
id: { type: "Identifier", name: "f" }, | ||
generator: false, | ||
async: false, | ||
params: [ | ||
{ type: "Identifier", name: "x" }, | ||
{ type: "Identifier", name: "x" }, | ||
], | ||
body: { | ||
type: "BlockStatement", | ||
body: [], | ||
directives: [], | ||
}, | ||
}); | ||
} | ||
|
||
function expectToFail(opts) { | ||
expect(() => parse(CODE, opts)).toThrow( | ||
new SyntaxError("Argument name clash. (1:14)"), | ||
); | ||
} | ||
|
||
describe("sourceType module", () => { | ||
it("default parses as strict mode", () => { | ||
expectToFail({ sourceType: "module" }); | ||
}); | ||
|
||
it("false parses as sloppy mode", () => { | ||
expectToSucceed({ sourceType: "module", strictMode: false }); | ||
}); | ||
|
||
it("true parses as strict mode", () => { | ||
expectToFail({ sourceType: "module", strictMode: true }); | ||
}); | ||
}); | ||
|
||
describe("sourceType script", () => { | ||
it("default parses as sloppy mode", () => { | ||
expectToSucceed({ sourceType: "script" }); | ||
}); | ||
|
||
it("false parses as sloppy mode", () => { | ||
expectToSucceed({ sourceType: "script", strictMode: false }); | ||
}); | ||
|
||
it("true parses as strict mode", () => { | ||
expectToFail({ sourceType: "script", strictMode: true }); | ||
}); | ||
}); | ||
}); | ||
}); |