Skip to content

Commit 529b405

Browse files
authored
refactor: expose as es module (#556)
* refactor: expose as es module * self reference
1 parent 243f068 commit 529b405

File tree

15 files changed

+56
-79
lines changed

15 files changed

+56
-79
lines changed

.eslintrc.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
"env": {
33
"browser": true,
44
"commonjs": true,
5-
"amd": true,
6-
"es6": true,
5+
"es2020": true,
76
"node": true,
87
"mocha": true
98
},

.github/workflows/nodejs.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ on: [push, pull_request]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
9-
108
strategy:
119
matrix:
12-
node-version: [10.x, 12.x, 14.x]
10+
node-version: [12.x, 14.x, 15.x]
1311

1412
steps:
1513
- uses: actions/checkout@v1

jsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
3-
"target": "es2019",
3+
"target": "es2020",
4+
"module": "es2020",
45
"moduleResolution": "node"
56
},
67
"include": [

lib/validator.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use strict";
2-
31
import { validationError as error } from "./error.js";
42

53
function getMixinMap(all, unique) {

lib/webidl2.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use strict";
2-
31
import { Tokeniser } from "./tokeniser.js";
42
import { Enum } from "./productions/enum.js";
53
import { Includes } from "./productions/includes.js";

lib/writer.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"use strict";
2-
31
function noop(arg) {
42
return arg;
53
}

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"Timothy Gu <[email protected]>"
1010
],
1111
"license": "W3C",
12-
"dependencies": {},
1312
"devDependencies": {
1413
"eslint": "^7.23.0",
1514
"eslint-plugin-import": "^2.22.1",
@@ -28,11 +27,13 @@
2827
"test": "npm run lint && webpack && mocha",
2928
"acquire": "node test/util/acquire.js",
3029
"build": "npx webpack",
31-
"build-debug": "npx webpack --mode none"
30+
"build-debug": "npx webpack --mode none",
31+
"prepublishOnly": "npm run build"
3232
},
3333
"repository": "git://github.com/w3c/webidl2.js",
3434
"main": "dist/webidl2.js",
35-
"module": "index.js",
35+
"exports": "./index.js",
36+
"type": "module",
3637
"files": [
3738
"dist/*",
3839
"lib/*",

test/autofix.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
"use strict";
2-
3-
const expect = require("expect");
4-
const webidl2 = require("../dist/webidl2.js");
1+
import expect from "expect";
2+
import { parse, validate, write } from "webidl2";
53

64
describe("Writer template functions", () => {
75
function autofix(idl) {
8-
const ast = webidl2.parse(idl, { concrete: true });
9-
const validations = webidl2.validate(ast);
6+
const ast = parse(idl, { concrete: true });
7+
const validations = validate(ast);
108
for (const v of validations) {
119
if (v.autofix) {
1210
v.autofix();
1311
}
1412
}
15-
return webidl2.write(ast);
13+
return write(ast);
1614
}
1715

1816
it("should add `= {}`", () => {

test/invalid.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
// - the errors actually still need to be reviewed to check that they
33
// are fully correct interpretations of the IDLs
44

5-
"use strict";
6-
7-
const { collect } = require("./util/collect");
8-
const { parse, validate, WebIDLParseError } = require("..");
9-
const expect = require("expect");
5+
import { collect } from "./util/collect.js";
6+
import { parse, validate, WebIDLParseError } from "webidl2";
7+
import expect from "expect";
108

119
describe("Parses all of the invalid IDLs to check that they blow up correctly", () => {
1210
for (const test of collect("invalid", { expectError: true, raw: true })) {

test/parent.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
"use strict";
2-
3-
const expect = require("expect");
4-
const webidl2 = require("../dist/webidl2");
1+
import expect from "expect";
2+
import { parse } from "webidl2";
53

64
function checkIdlType(idlType) {
75
if (idlType.subtype) {
@@ -80,7 +78,7 @@ function checkParent(data) {
8078
* @param {string} idl
8179
*/
8280
function parseAndCheck(idl) {
83-
const tree = webidl2.parse(idl);
81+
const tree = parse(idl);
8482
for (const item of tree) {
8583
checkParent(item);
8684
}

0 commit comments

Comments
 (0)