Skip to content

Commit e6d8ab8

Browse files
authored
feat: add type field for WrappedToken (#822)
* feat: add type field for WrappedToken One could check the list type to see the child type, but this may provide extra convenience if the caller wants to do something like `list.value.map(forEachValue)` Fixes #818 * Update README.md
1 parent 9d0c8f3 commit e6d8ab8

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ Extended attributes look like this:
720720
* `type`: Always `"extended-attribute"`.
721721
* `rhs`: If there is a right-hand side, this will capture its `type` and `value`. The
722722
type can be one of the following:
723+
723724
* `"identifier"`
724725
* `"identifier-list"`
725726
* `"string"`
@@ -729,6 +730,8 @@ Extended attributes look like this:
729730
* `"integer"`
730731
* `"integer-list"`
731732
* `"*"`
733+
734+
Each child of a list has its own `type` of `value`, e.g. `type: "identifier"` for `"identifier-list"`.
732735
* `parent`: The container of this type as an Object.
733736

734737
### Default and Const Values

lib/productions/token.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export class WrappedToken extends Base {
1818
};
1919
}
2020

21+
get type() {
22+
return this.tokens.value.type;
23+
}
24+
2125
get value() {
2226
return unescape(this.tokens.value.value);
2327
}

test/syntax/baseline/extended-attributes.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
"type": "identifier-list",
1313
"value": [
1414
{
15+
"type": "identifier",
1516
"value": "Worker"
1617
},
1718
{
19+
"type": "identifier",
1820
"value": "ServiceWorker"
1921
}
2022
]
@@ -82,9 +84,11 @@
8284
"type": "identifier-list",
8385
"value": [
8486
{
87+
"type": "identifier",
8588
"value": "null"
8689
},
8790
{
91+
"type": "identifier",
8892
"value": "const"
8993
}
9094
]
@@ -98,6 +102,7 @@
98102
"type": "decimal-list",
99103
"value": [
100104
{
105+
"type": "decimal",
101106
"value": "3.14"
102107
}
103108
]

test/syntax/baseline/reflector-interface.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,11 @@
6363
"type": "string-list",
6464
"value": [
6565
{
66+
"type": "string",
6667
"value": "\"anonymous\""
6768
},
6869
{
70+
"type": "string",
6971
"value": "\"use-credentials\""
7072
}
7173
]
@@ -101,9 +103,11 @@
101103
"type": "integer-list",
102104
"value": [
103105
{
106+
"type": "integer",
104107
"value": "1"
105108
},
106109
{
110+
"type": "integer",
107111
"value": "4"
108112
}
109113
]

0 commit comments

Comments
 (0)