Skip to content

Commit 2a44c39

Browse files
authored
Update AST (#3)
* Update AST * update
1 parent f25c4f6 commit 2a44c39

File tree

9 files changed

+63
-9
lines changed

9 files changed

+63
-9
lines changed

.github/workflows/NodeCI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ jobs:
5757
- name: Test
5858
run: npm run test:nyc
5959
- name: Coveralls GitHub Action
60-
uses: coverallsapp/github-action@v1.0.1
60+
uses: coverallsapp/github-action@v1.1.1
6161
with:
6262
github-token: ${{ secrets.GITHUB_TOKEN }}

lib/parser/ast.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ export interface JSONProperty extends BaseJSONNode {
6565
type: "JSONProperty"
6666
key: JSONIdentifier | JSONLiteral
6767
value: JSONExpression
68+
kind: "init"
69+
method: false
70+
shorthand: false
71+
computed: false
6872
parent?: JSONObjectExpression
6973
}
7074

lib/parser/convert.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ function convertPropertyNode(
172172
type: "JSONProperty",
173173
key: convertNode(node.key, tokens) as JSONLiteral | JSONIdentifier,
174174
value: convertNode(node.value, tokens) as JSONExpression,
175+
kind: node.kind,
176+
computed: node.computed,
177+
method: node.method,
178+
shorthand: node.shorthand,
175179
...getFixLocation(node),
176180
}
177181
checkUnexpectKeys(node, tokens, nn)
@@ -284,7 +288,7 @@ function convertUnaryExpressionNode(
284288
const nn: JSONUnaryExpression = {
285289
type: "JSONUnaryExpression",
286290
operator,
287-
prefix: true,
291+
prefix: node.prefix,
288292
argument: convertNode(argument, tokens) as
289293
| JSONNumberLiteral
290294
| JSONNumberIdentifier,

lib/utils/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,12 @@ export function defineWrapperListener(
7272
* Get the proxy node
7373
*/
7474
function getProxyNode(node: JSONNode): any {
75-
const cache: any = {}
7675
const type = node.type.startsWith("JSON")
7776
? node.type.slice(4)
7877
: node.type
78+
const cache: any = { type }
7979
return new Proxy(node, {
8080
get(_t, key) {
81-
if (key === "type") {
82-
return type
83-
}
84-
if (key === "kind" && node.type === "JSONProperty") {
85-
return "init"
86-
}
8781
if (key in cache) {
8882
return cache[key]
8983
}

tests/fixtures/parser/ast/infinity-02-output.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
}
4545
}
4646
},
47+
"kind": "init",
48+
"computed": false,
49+
"method": false,
50+
"shorthand": false,
4751
"range": [
4852
6,
4953
17
@@ -116,6 +120,10 @@
116120
}
117121
}
118122
},
123+
"kind": "init",
124+
"computed": false,
125+
"method": false,
126+
"shorthand": false,
119127
"range": [
120128
23,
121129
35
@@ -188,6 +196,10 @@
188196
}
189197
}
190198
},
199+
"kind": "init",
200+
"computed": false,
201+
"method": false,
202+
"shorthand": false,
191203
"range": [
192204
41,
193205
52

tests/fixtures/parser/ast/nan-02-output.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
}
4545
}
4646
},
47+
"kind": "init",
48+
"computed": false,
49+
"method": false,
50+
"shorthand": false,
4751
"range": [
4852
6,
4953
12
@@ -116,6 +120,10 @@
116120
}
117121
}
118122
},
123+
"kind": "init",
124+
"computed": false,
125+
"method": false,
126+
"shorthand": false,
119127
"range": [
120128
18,
121129
25
@@ -188,6 +196,10 @@
188196
}
189197
}
190198
},
199+
"kind": "init",
200+
"computed": false,
201+
"method": false,
202+
"shorthand": false,
191203
"range": [
192204
31,
193205
37

tests/fixtures/parser/ast/object-01-output.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
}
4747
}
4848
},
49+
"kind": "init",
50+
"computed": false,
51+
"method": false,
52+
"shorthand": false,
4953
"range": [
5054
1,
5155
12

tests/fixtures/parser/ast/object-02-output.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
}
6969
}
7070
},
71+
"kind": "init",
72+
"computed": false,
73+
"method": false,
74+
"shorthand": false,
7175
"range": [
7276
21,
7377
27
@@ -123,6 +127,10 @@
123127
}
124128
}
125129
},
130+
"kind": "init",
131+
"computed": false,
132+
"method": false,
133+
"shorthand": false,
126134
"range": [
127135
37,
128136
45
@@ -154,6 +162,10 @@
154162
}
155163
}
156164
},
165+
"kind": "init",
166+
"computed": false,
167+
"method": false,
168+
"shorthand": false,
157169
"range": [
158170
6,
159171
51

tests/fixtures/parser/ast/object-03-output.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
}
7070
}
7171
},
72+
"kind": "init",
73+
"computed": false,
74+
"method": false,
75+
"shorthand": false,
7276
"range": [
7377
23,
7478
29
@@ -123,6 +127,10 @@
123127
}
124128
}
125129
},
130+
"kind": "init",
131+
"computed": false,
132+
"method": false,
133+
"shorthand": false,
126134
"range": [
127135
39,
128136
45
@@ -154,6 +162,10 @@
154162
}
155163
}
156164
},
165+
"kind": "init",
166+
"computed": false,
167+
"method": false,
168+
"shorthand": false,
157169
"range": [
158170
6,
159171
52

0 commit comments

Comments
 (0)