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

Remove source transform and add benchmark #194

Merged
merged 1 commit into from
Sep 12, 2021
Merged
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
6 changes: 5 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
coverage/
dist/
test/web-platform-tests/
live-viewer/whatwg-url.js
lib/VoidFunction.js
lib/Function.js
lib/URL.js
lib/URLSearchParams.js
lib/utils.js
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ npm-debug.log
# project specific
coverage/
test/web-platform-tests/
dist/
out/
live-viewer/whatwg-url.js
lib/VoidFunction.js
lib/Function.js
lib/URL.js
lib/URLSearchParams.js
lib/utils.js
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";

const { URL, URLSearchParams } = require("./webidl2js-wrapper");
const urlStateMachine = require("./dist/url-state-machine");
const percentEncoding = require("./dist/percent-encoding");
const urlStateMachine = require("./lib/url-state-machine");
const percentEncoding = require("./lib/percent-encoding");

const sharedGlobalObject = {};
URL.install(sharedGlobalObject, ["Window"]);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2,942 changes: 1,597 additions & 1,345 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"files": [
"index.js",
"webidl2js-wrapper.js",
"dist/"
"lib/*.js"
],
"author": "Sebastian Mayr <[email protected]>",
"license": "MIT",
Expand All @@ -17,13 +17,12 @@
},
"devDependencies": {
"@domenic/eslint-config": "^1.2.0",
"benchmark": "^2.1.4",
"browserify": "^17.0.0",
"domexception": "^2.0.1",
"eslint": "^7.29.0",
"glob": "^7.1.7",
"got": "^11.8.2",
"jest": "^27.0.5",
"recast": "^0.20.4",
"webidl2js": "^16.2.0"
},
"engines": {
Expand Down
20 changes: 20 additions & 0 deletions scripts/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";
const { URL } = require("../");
const Benchmark = require("benchmark");
const testData = require("../test/web-platform-tests/resources/urltestdata.json");

const testInputs = testData.filter(c => typeof c === "object").map(c => c.input);

const benchmark = new Benchmark(() => {
for (const input of testInputs) {
try {
// eslint-disable-next-line no-new
new URL(input);
} catch {
// intentionally empty
}
}
});

benchmark.on("cycle", e => console.log(e.target.toString()));
benchmark.run();
47 changes: 3 additions & 44 deletions scripts/transform.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,14 @@
"use strict";

const fs = require("fs");
const path = require("path");
const recast = require("recast");
const glob = require("glob");
const WebIDL2JS = require("webidl2js");

const srcDir = path.resolve(__dirname, "../src");
const outputDir = path.resolve(__dirname, "../dist");

(fs.rmSync || fs.rmdirSync)(outputDir, { recursive: true, force: true });
fs.mkdirSync(outputDir, { recursive: true });

for (const file of glob.sync(`${srcDir}/*.js`)) {
const code = fs.readFileSync(file, { encoding: "utf8" });
const ast = recast.parse(code);
replaceP(ast.program.body);
const output = recast.print(ast, { lineTerminator: "\n" }).code;

const outputFile = path.resolve(outputDir, path.relative(srcDir, file));
fs.writeFileSync(outputFile, output);
}
const dir = path.resolve(__dirname, "../lib");

const transformer = new WebIDL2JS({ implSuffix: "-impl" });

transformer.addSource(srcDir, outputDir);
transformer.generate(outputDir)
transformer.addSource(dir, dir);
transformer.generate(dir)
.catch(err => {
console.error(err.stack);
process.exit(1);
});

function replaceP(body) {
recast.types.visit(body, {
/* eslint-disable consistent-return */
visitFunction(p) {
if (p.node.id && p.node.id.name === "p") {
p.replace();
return false;
}

this.traverse(p);
},

visitCallExpression(p) {
if (p.node.callee.name === "p") {
const codePoint = p.node.arguments[0].value.codePointAt(0);
p.replace(recast.types.builders.literal(codePoint));
}

this.traverse(p);
}
});
}
2 changes: 1 addition & 1 deletion test/web-platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const assert = require("assert");
const fs = require("fs");
const path = require("path");
const vm = require("vm");
const { utf8PercentEncodeString, isSpecialQueryPercentEncode } = require("../dist/percent-encoding.js");
const { utf8PercentEncodeString, isSpecialQueryPercentEncode } = require("../lib/percent-encoding.js");
const { URL, URLSearchParams } = require("..");
const DOMException = require("domexception");
const testharness = require("./testharness");
Expand Down
4 changes: 2 additions & 2 deletions webidl2js-wrapper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const URL = require("./dist/URL");
const URLSearchParams = require("./dist/URLSearchParams");
const URL = require("./lib/URL");
const URLSearchParams = require("./lib/URLSearchParams");

exports.URL = URL;
exports.URLSearchParams = URLSearchParams;