Skip to content

Commit

Permalink
feat: support [Exposed=*] (#634)
Browse files Browse the repository at this point in the history
* reformat webpack config

* feat: support `[Exposed=*]`

* fix writer
  • Loading branch information
saschanaz authored Nov 3, 2021
1 parent c1131e3 commit 743f84c
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ Extended attributes look like this:
* `"decimal-list"`
* `"integer"`
* `"integer-list"`
* `"*"`
* `parent`: The container of this type as an Object.

### Default and Const Values
Expand Down
29 changes: 20 additions & 9 deletions lib/productions/extended-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ class ExtendedAttributeParameters extends Base {
const ret = autoParenter(
new ExtendedAttributeParameters({ source: tokeniser.source, tokens })
);
ret.list = [];
if (tokens.assign) {
tokens.asterisk = tokeniser.consume("*");
if (tokens.asterisk) {
return ret.this;
}
tokens.secondaryName = tokeniser.consumeKind(...extAttrValueSyntax);
}
tokens.open = tokeniser.consume("(");
Expand All @@ -77,13 +82,18 @@ class ExtendedAttributeParameters extends Base {
}

get rhsIsList() {
return this.tokens.assign && !this.tokens.secondaryName;
return (
this.tokens.assign && !this.tokens.asterisk && !this.tokens.secondaryName
);
}

get rhsType() {
if (this.rhsIsList) {
return this.list[0].tokens.value.type + "-list";
}
if (this.tokens.asterisk) {
return "*";
}
if (this.tokens.secondaryName) {
return this.tokens.secondaryName.type;
}
Expand All @@ -95,15 +105,14 @@ class ExtendedAttributeParameters extends Base {
const { rhsType } = this;
return w.ts.wrap([
w.token(this.tokens.assign),
w.token(this.tokens.asterisk),
w.reference_token(this.tokens.secondaryName, this.parent),
w.token(this.tokens.open),
...(!this.list
? []
: this.list.map((p) => {
return rhsType === "identifier-list"
? w.identifier(p, this.parent)
: p.write(w);
})),
...this.list.map((p) => {
return rhsType === "identifier-list"
? w.identifier(p, this.parent)
: p.write(w);
}),
w.token(this.tokens.close),
]);
}
Expand Down Expand Up @@ -143,7 +152,9 @@ export class SimpleExtendedAttribute extends Base {
}
const value = this.params.rhsIsList
? list
: unescape(tokens.secondaryName.value);
: this.params.tokens.secondaryName
? unescape(tokens.secondaryName.value)
: null;
return { type, value };
}
get arguments() {
Expand Down
1 change: 1 addition & 0 deletions lib/tokeniser.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const punctuations = [
"=",
">",
"?",
"*",
"[",
"]",
"{",
Expand Down
24 changes: 24 additions & 0 deletions test/syntax/baseline/exposed-asterisk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
{
"type": "interface",
"name": "X",
"inheritance": null,
"members": [],
"extAttrs": [
{
"type": "extended-attribute",
"name": "Exposed",
"rhs": {
"type": "*",
"value": null
},
"arguments": []
}
],
"partial": false
},
{
"type": "eof",
"value": ""
}
]
2 changes: 2 additions & 0 deletions test/syntax/idl/exposed-asterisk.webidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Exposed=*]
interface X {};
14 changes: 7 additions & 7 deletions webpack.config.cjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const path = require("path");
const TerserPlugin = require('terser-webpack-plugin');
const TerserPlugin = require("terser-webpack-plugin");
module.exports = {
entry: "./index.js",
output: {
filename: "webidl2.js",
path: path.resolve(__dirname, "dist"),
library: "WebIDL2",
libraryTarget: "umd",
globalObject: "globalThis"
globalObject: "globalThis",
},
mode: "production",
devtool: "source-map",
Expand All @@ -16,9 +16,9 @@ module.exports = {
new TerserPlugin({
terserOptions: {
keep_classnames: true,
sourceMap: true
}
})
]
}
sourceMap: true,
},
}),
],
},
};

0 comments on commit 743f84c

Please sign in to comment.