Skip to content

Commit c51a6c9

Browse files
committed
Remove source transform and add benchmark
Closes #155.
1 parent 63625c6 commit c51a6c9

18 files changed

+1637
-1400
lines changed

.eslintignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
coverage/
2-
dist/
32
test/web-platform-tests/
43
live-viewer/whatwg-url.js
4+
lib/VoidFunction.js
5+
lib/Function.js
6+
lib/URL.js
7+
lib/URLSearchParams.js
8+
lib/utils.js

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ npm-debug.log
55
# project specific
66
coverage/
77
test/web-platform-tests/
8-
dist/
9-
out/
108
live-viewer/whatwg-url.js
9+
lib/VoidFunction.js
10+
lib/Function.js
11+
lib/URL.js
12+
lib/URLSearchParams.js
13+
lib/utils.js

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use strict";
22

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

77
const sharedGlobalObject = {};
88
URL.install(sharedGlobalObject, ["Window"]);
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.

package-lock.json

Lines changed: 1597 additions & 1345 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"files": [
77
"index.js",
88
"webidl2js-wrapper.js",
9-
"dist/"
9+
"lib/*.js"
1010
],
1111
"author": "Sebastian Mayr <[email protected]>",
1212
"license": "MIT",
@@ -17,13 +17,12 @@
1717
},
1818
"devDependencies": {
1919
"@domenic/eslint-config": "^1.2.0",
20+
"benchmark": "^2.1.4",
2021
"browserify": "^17.0.0",
2122
"domexception": "^2.0.1",
2223
"eslint": "^7.29.0",
23-
"glob": "^7.1.7",
2424
"got": "^11.8.2",
2525
"jest": "^27.0.5",
26-
"recast": "^0.20.4",
2726
"webidl2js": "^16.2.0"
2827
},
2928
"engines": {

scripts/benchmark.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
const { URL } = require("../");
3+
const Benchmark = require("benchmark");
4+
const testData = require("../test/web-platform-tests/resources/urltestdata.json");
5+
6+
const testInputs = testData.filter(c => typeof c === "object").map(c => c.input);
7+
8+
const benchmark = new Benchmark(() => {
9+
for (const input of testInputs) {
10+
try {
11+
// eslint-disable-next-line no-new
12+
new URL(input);
13+
} catch {
14+
// intentionally empty
15+
}
16+
}
17+
});
18+
19+
benchmark.on("cycle", e => console.log(e.target.toString()));
20+
benchmark.run();

scripts/transform.js

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,14 @@
11
"use strict";
2-
3-
const fs = require("fs");
42
const path = require("path");
5-
const recast = require("recast");
6-
const glob = require("glob");
73
const WebIDL2JS = require("webidl2js");
84

9-
const srcDir = path.resolve(__dirname, "../src");
10-
const outputDir = path.resolve(__dirname, "../dist");
11-
12-
(fs.rmSync || fs.rmdirSync)(outputDir, { recursive: true, force: true });
13-
fs.mkdirSync(outputDir, { recursive: true });
14-
15-
for (const file of glob.sync(`${srcDir}/*.js`)) {
16-
const code = fs.readFileSync(file, { encoding: "utf8" });
17-
const ast = recast.parse(code);
18-
replaceP(ast.program.body);
19-
const output = recast.print(ast, { lineTerminator: "\n" }).code;
20-
21-
const outputFile = path.resolve(outputDir, path.relative(srcDir, file));
22-
fs.writeFileSync(outputFile, output);
23-
}
5+
const dir = path.resolve(__dirname, "../lib");
246

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

27-
transformer.addSource(srcDir, outputDir);
28-
transformer.generate(outputDir)
9+
transformer.addSource(dir, dir);
10+
transformer.generate(dir)
2911
.catch(err => {
3012
console.error(err.stack);
3113
process.exit(1);
3214
});
33-
34-
function replaceP(body) {
35-
recast.types.visit(body, {
36-
/* eslint-disable consistent-return */
37-
visitFunction(p) {
38-
if (p.node.id && p.node.id.name === "p") {
39-
p.replace();
40-
return false;
41-
}
42-
43-
this.traverse(p);
44-
},
45-
46-
visitCallExpression(p) {
47-
if (p.node.callee.name === "p") {
48-
const codePoint = p.node.arguments[0].value.codePointAt(0);
49-
p.replace(recast.types.builders.literal(codePoint));
50-
}
51-
52-
this.traverse(p);
53-
}
54-
});
55-
}

test/web-platform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const assert = require("assert");
33
const fs = require("fs");
44
const path = require("path");
55
const vm = require("vm");
6-
const { utf8PercentEncodeString, isSpecialQueryPercentEncode } = require("../dist/percent-encoding.js");
6+
const { utf8PercentEncodeString, isSpecialQueryPercentEncode } = require("../lib/percent-encoding.js");
77
const { URL, URLSearchParams } = require("..");
88
const DOMException = require("domexception");
99
const testharness = require("./testharness");

webidl2js-wrapper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

3-
const URL = require("./dist/URL");
4-
const URLSearchParams = require("./dist/URLSearchParams");
3+
const URL = require("./lib/URL");
4+
const URLSearchParams = require("./lib/URLSearchParams");
55

66
exports.URL = URL;
77
exports.URLSearchParams = URLSearchParams;

0 commit comments

Comments
 (0)