/
githubmirror
/
babel
Обзор
Документация
Войти
/
githubmirror
/
babel
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/babel-parser/test/options.js
117 строк
3 KB
liuxingbaoyu
Remove `locations: "packed"` (#18034)
01 июн 2026, 00:36
Не верифицирован
01 июн 2026, 00:36
05eb4be
Код
Авторство
О чём код?
import { parse } from "../lib/index.js"; 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 }); }); }); describe("locations", () => { it("false", () => { expect(parse(CODE, { locations: false })).toMatchInlineSnapshot(` Node { "comments": [], "end": 19, "errors": [], "program": Node { "body": [ Node { "async": false, "body": Node { "body": [], "directives": [], "end": 19, "start": 17, "type": "BlockStatement", }, "end": 19, "generator": false, "id": Node { "end": 10, "name": "f", "start": 9, "type": "Identifier", }, "params": [ Node { "end": 12, "name": "x", "start": 11, "type": "Identifier", }, Node { "end": 15, "name": "x", "start": 14, "type": "Identifier", }, ], "start": 0, "type": "FunctionDeclaration", }, ], "directives": [], "end": 19, "interpreter": null, "sourceType": "script", "start": 0, "type": "Program", }, "start": 0, "type": "File", } `); }); }); }); });