Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib depends: Upgrade pegjs to peggy #1221

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-include .env
export

PEGJS ?= npx pegjs
PEGJS ?= npx peggy
SASS ?= npx sass
YARN ?= npx yarn

Expand Down Expand Up @@ -48,7 +48,7 @@ build: bundle css

.PHONY: depends-parser
depends-parser: stamp-yarn
$(PEGJS) -O size -f es src/lib/depends_parse.pegjs
$(PEGJS) --format es src/lib/depends_parse.pegjs


# Unlink any linked dependencies before building a bundle.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"copy-webpack-plugin": "^12.0.2",
"css.escape": "^1.5.1",
"modernizr": "^3.13.1",
"pegjs": "0.11.0-master.b7b87ea"
"peggy": "^4.2.0"
},
"resolutions": {
"jquery": "3.7.1"
Expand Down
1,941 changes: 1,433 additions & 508 deletions src/lib/depends_parse.js

Large diffs are not rendered by default.

32 changes: 16 additions & 16 deletions src/lib/depends_parse.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import parser from "./depends_parse";
import { parse } from "./depends_parse";

describe("Depedency expression parser", function () {
describe("Simple expressions", function () {
it("Input has a value", function () {
var ast = parser.parse("foo");
var ast = parse("foo");
expect(ast).toEqual({ type: "truthy", input: "foo" });
});

it("Input has a specific value", function () {
var ast = parser.parse("foo=15");
var ast = parse("foo=15");
expect(ast).toEqual({
type: "comparison",
input: "foo",
Expand All @@ -18,7 +18,7 @@ describe("Depedency expression parser", function () {
});

it("Order comparision", function () {
var ast = parser.parse("foo>=15");
var ast = parse("foo>=15");
expect(ast).toEqual({
type: "comparison",
input: "foo",
Expand All @@ -29,12 +29,12 @@ describe("Depedency expression parser", function () {

it("Can not do order comparison to string", function () {
expect(function () {
parser.parse("foo<bar");
parse("foo<bar");
}).toThrowError('Expected number or whitespace but "b" found.');
});

it("Equality comparison with string", function () {
var ast = parser.parse("foo=bar");
var ast = parse("foo=bar");
expect(ast).toEqual({
type: "comparison",
input: "foo",
Expand All @@ -44,7 +44,7 @@ describe("Depedency expression parser", function () {
});

it("Wrapped simple expression", function () {
var ast = parser.parse("(foo=15)");
var ast = parse("(foo=15)");
expect(ast).toEqual({
type: "comparison",
input: "foo",
Expand All @@ -54,7 +54,7 @@ describe("Depedency expression parser", function () {
});

it("Unicode value", function () {
var ast = parser.parse("føø=bar");
var ast = parse("føø=bar");
expect(ast).toEqual({
type: "comparison",
input: "føø",
Expand All @@ -64,7 +64,7 @@ describe("Depedency expression parser", function () {
});

it("Unicode value", function () {
var ast = parser.parse("foo=bær");
var ast = parse("foo=bær");
expect(ast).toEqual({
type: "comparison",
input: "foo",
Expand All @@ -74,17 +74,17 @@ describe("Depedency expression parser", function () {
});

it("Dashes in name", function () {
var ast = parser.parse("foo-bar");
var ast = parse("foo-bar");
expect(ast).toEqual({ type: "truthy", input: "foo-bar" });
});

it("Colons in name", function () {
var ast = parser.parse("foo:bar");
var ast = parse("foo:bar");
expect(ast).toEqual({ type: "truthy", input: "foo:bar" });
});

it("Single quoted value", function () {
var ast = parser.parse("foo='bar buz'");
var ast = parse("foo='bar buz'");
expect(ast).toEqual({
type: "comparison",
input: "foo",
Expand All @@ -94,7 +94,7 @@ describe("Depedency expression parser", function () {
});

it("Double quoted value", function () {
var ast = parser.parse('foo="bar buz"');
var ast = parse('foo="bar buz"');
expect(ast).toEqual({
type: "comparison",
input: "foo",
Expand All @@ -106,7 +106,7 @@ describe("Depedency expression parser", function () {

describe("Expressions", function () {
it("Negated simple expression", function () {
var ast = parser.parse("not foo=15");
var ast = parse("not foo=15");
expect(ast).toEqual({
type: "NOT",
children: [
Expand All @@ -121,7 +121,7 @@ describe("Depedency expression parser", function () {
});

it("OR two simple expressions", function () {
var ast = parser.parse("foo or baf");
var ast = parse("foo or baf");
expect(ast).toEqual({
type: "OR",
children: [
Expand All @@ -132,7 +132,7 @@ describe("Depedency expression parser", function () {
});

it("Complex expression", function () {
var ast = parser.parse("foo or not (bar=1 and buz)");
var ast = parse("foo or not (bar=1 and buz)");
expect(ast).toEqual({
type: "OR",
children: [
Expand Down
4 changes: 2 additions & 2 deletions src/lib/dependshandler.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import parser from "./depends_parse";
import { parse } from "./depends_parse";

class DependsHandler {
constructor(el, expression) {
this.el = el;
this.context = el.closest("form") || document;
this.ast = parser.parse(expression); // TODO: handle parse exceptions here
this.ast = parse(expression); // TODO: handle parse exceptions here
}

_findInputs(name) {
Expand Down
39 changes: 30 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,13 @@
jquery "^3.6.1"
underscore "^1.13.4"

"@peggyjs/from-mem@1.3.5":
version "1.3.5"
resolved "https://registry.yarnpkg.com/@peggyjs/from-mem/-/from-mem-1.3.5.tgz#d6294c588517728f73cc6c091706e147f8824be0"
integrity sha512-oRyzXE7nirAn+5yYjCdWQHg3EG2XXcYRoYNOK8Quqnmm+9FyK/2YWVunwudlYl++M3xY+gIAdf0vAYS+p0nKfQ==
dependencies:
semver "7.6.3"

"@pkgjs/parseargs@^0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
Expand Down Expand Up @@ -3339,6 +3346,11 @@ commander@^10.0.1:
resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06"
integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==

commander@^12.1.0:
version "12.1.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3"
integrity sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==

commander@^2.20.0:
version "2.20.3"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
Expand Down Expand Up @@ -6934,10 +6946,14 @@ path-type@^5.0.0:
resolved "https://registry.yarnpkg.com/path-type/-/path-type-5.0.0.tgz#14b01ed7aea7ddf9c7c3f46181d4d04f9c785bb8"
integrity sha512-5HviZNaZcfqP95rwpv+1HDgUamezbqdSYTyzjTvwtJSnIH+3vnbmWsItli8OFEndS984VT55M3jduxZbX351gg==

pegjs@0.11.0-master.b7b87ea:
version "0.11.0-master.b7b87ea"
resolved "https://registry.yarnpkg.com/pegjs/-/pegjs-0.11.0-master.b7b87ea.tgz#dc41190696bc33c8a09210a0bf91e683d4f1d6dc"
integrity sha512-fwjzNiYHRUEUe/86Aaslb/ocbbsAupOcsJz+dlPYtgp3feCDRQOLChHO924XGh7fzSJBTdFCQTzmSOQaWjCTew==
peggy@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/peggy/-/peggy-4.2.0.tgz#9ce13fef2710357e881b57c41d426dbe90e9a001"
integrity sha512-ZjzyJYY8NqW8JOZr2PbS/J0UH/hnfGALxSDsBUVQg5Y/I+ZaPuGeBJ7EclUX2RvWjhlsi4pnuL1C/K/3u+cDeg==
dependencies:
"@peggyjs/from-mem" "1.3.5"
commander "^12.1.0"
source-map-generator "0.8.0"

photoswipe@^4.1.3:
version "4.1.3"
Expand Down Expand Up @@ -7757,16 +7773,16 @@ semver@7.6.2:
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.2.tgz#1e3b34759f896e8f14d6134732ce798aeb0c6e13"
integrity sha512-FNAIBWCx9qcRhoHcgcJ0gvU7SN1lYU2ZXuSfl04bSC5OpvDHFyJCjdNHomPXxjQlCBU67YW64PzY7/VIEH7F2w==

semver@7.6.3, semver@^7.3.5, semver@^7.5.2, semver@^7.5.3, semver@^7.5.4, semver@^7.6.0, semver@^7.6.2:
version "7.6.3"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143"
integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==

semver@^6.3.0, semver@^6.3.1:
version "6.3.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==

semver@^7.3.5, semver@^7.5.2, semver@^7.5.3, semver@^7.5.4, semver@^7.6.0, semver@^7.6.2:
version "7.6.3"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143"
integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==

send@0.18.0:
version "0.18.0"
resolved "https://registry.yarnpkg.com/send/-/send-0.18.0.tgz#670167cc654b05f5aa4a767f9113bb371bc706be"
Expand Down Expand Up @@ -7980,6 +7996,11 @@ socks@^2.8.3:
ip-address "^9.0.5"
smart-buffer "^4.2.0"

source-map-generator@0.8.0:
version "0.8.0"
resolved "https://registry.yarnpkg.com/source-map-generator/-/source-map-generator-0.8.0.tgz#10d5ca0651e2c9302ea338739cbd4408849c5d00"
integrity sha512-psgxdGMwl5MZM9S3FWee4EgsEaIjahYV5AzGnwUvPhWeITz/j6rKpysQHlQ4USdxvINlb8lKfWGIXwfkrgtqkA==

"source-map-js@>=0.6.2 <2.0.0", source-map-js@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/source-map-js/-/source-map-js-1.2.0.tgz#16b809c162517b5b8c3e7dcd315a2a5c2612b2af"
Expand Down
Loading