Skip to content

Commit

Permalink
Merge pull request #521 from hildjj/constructor
Browse files Browse the repository at this point in the history
Allow "constructor" and other object properties as grammar literals
  • Loading branch information
hildjj authored Jun 19, 2024
2 parents 35968c8 + 782e345 commit c433373
Show file tree
Hide file tree
Showing 11 changed files with 810 additions and 755 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Unreleased
### Bug fixes
- [#507](https://github.com/peggyjs/peggy/pull/507) Remove stray semicolon in CSS
- [#508](https://github.com/peggyjs/peggy/pull/508) Fix broken text input
- [#520](https://github.com/peggyjs/peggy/pull/520) Grammar with token "constructor" fails to generate

### Documentation
- [#506](https://github.com/peggyjs/peggy/pull/506) Added END OF INPUT (`!.`).
Expand Down
2 changes: 1 addition & 1 deletion docs/js/benchmark-bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/js/test-bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/vendor/peggy/peggy.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/compiler/intern.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Intern {
/** @type {V[]} */
this.items = [];
/** @type {Record<string, number>} */
this.offsets = {};
this.offsets = Object.create(null);
}

/**
Expand Down
541 changes: 276 additions & 265 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,32 +54,32 @@
},
"devDependencies": {
"@peggyjs/eslint-config": "^3.2.4",
"@rollup/plugin-commonjs": "^25.0.8",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-multi-entry": "^6.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.6",
"@types/chai": "^4.3.11",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.12",
"@typescript-eslint/eslint-plugin": "^7.11.0",
"@typescript-eslint/parser": "^7.11.0",
"@types/node": "^20.14.5",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"chai": "^4.3.11",
"chai-like": "^1.1.1",
"copyfiles": "^2.4.1",
"eslint": "^8.57.0",
"eslint-plugin-compat": "4.2.0",
"eslint-plugin-compat": "5.0.0",
"eslint-plugin-mocha": "10.4.3",
"express": "4.19.2",
"glob": "^10.4.1",
"glob": "^10.4.2",
"jest": "^29.7.0",
"rimraf": "^5.0.7",
"rollup": "^4.18.0",
"rollup-plugin-ignore": "1.0.10",
"source-map": "^0.8.0-beta.0",
"terser": "^5.31.0",
"ts-jest": "^29.1.3",
"tslib": "^2.6.2",
"terser": "^5.31.1",
"ts-jest": "^29.1.5",
"tslib": "^2.6.3",
"typescript": "^5.4.5"
},
"dependencies": {
Expand All @@ -90,7 +90,7 @@
"browserslist": [
"defaults, maintained node versions, not op_mini all"
],
"packageManager": "pnpm@9.1.2",
"packageManager": "pnpm@9.4.0",
"engines": {
"node": ">=18"
}
Expand Down
808 changes: 403 additions & 405 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions test/unit/compiler/passes/generate-bytecode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ describe("compiler pass |generateBytecode|", () => {
});
});

it("allows Object prototype property names as literals", () => {
expect(pass).to.changeAST([
"a = '__proto__'",
"b = 'constructor'",
"c = 'hasOwnProperty'",
"d = 'isPrototypeOf'",
"e = 'propertyIsEnumerable'",
"f = 'toLocaleString'",
"g = 'toString'",
"h = 'valueOf'",
].join("\n"), {
rules: [
{ bytecode: [18, 0, 2, 2, 22, 0, 23, 0] },
{ bytecode: [18, 1, 2, 2, 22, 1, 23, 1] },
{ bytecode: [18, 2, 2, 2, 22, 2, 23, 2] },
{ bytecode: [18, 3, 2, 2, 22, 3, 23, 3] },
{ bytecode: [18, 4, 2, 2, 22, 4, 23, 4] },
{ bytecode: [18, 5, 2, 2, 22, 5, 23, 5] },
{ bytecode: [18, 6, 2, 2, 22, 6, 23, 6] },
{ bytecode: [18, 7, 2, 2, 22, 7, 23, 7] },
],
});
});

it("defines correct constants", () => {
expect(pass).to.changeAST([
"a = 'a'",
Expand Down
2 changes: 1 addition & 1 deletion web-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "Joe Hildebrand <joe-github@cursive.net>",
"license": "MIT",
"devDependencies": {
"puppeteer": "22.10.0"
"puppeteer": "22.11.2"
},
"engines": {
"node": ">=16"
Expand Down
Loading

0 comments on commit c433373

Please sign in to comment.