Skip to content

Commit 3d5f2c1

Browse files
committed
Fix AssocExpression walking, and ConditionalExpression and SwitchStatement parsing
* Recognize ObjectExpressoinas AssocExpressoin for comatibility. * Do not crash on unfinished switch statement. * Fix walking of consequent and alternate of ConditionalExpression. * Upgrade dependencies.
1 parent 7405559 commit 3d5f2c1

File tree

7 files changed

+73
-69
lines changed

7 files changed

+73
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
coverage
66
dist/bin
77
dist/*.[jm]*
8+
pkg/walker/dist/*.[jm]*
89
node_modules
910
npm-debug.log

dist/index.d.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ export type Expression = BinaryExpression | ConditionalExpression
361361

362362
export interface ConditionalExpression extends Node {
363363
type: 'ConditionalExpression'
364-
test: Expression
365-
consequent: Statement[]
366-
alternate: Statement[]
364+
test: BinaryExpression
365+
consequent: Expression
366+
alternate: Expression
367367
}
368368

369369
export interface BinaryExpression extends Node {
@@ -439,7 +439,7 @@ export interface CallExpression extends Node {
439439

440440
export type PrimaryExpression = XlateExpression | ParenthesisExpression |
441441
ThisExpression | SuperExpression | AssocExpression | ListExpression |
442-
ListComprehension | ObjectName | Identifier | Literal
442+
ListComprehension | ObjectName | Identifier | Literal | ObjectExpression
443443

444444
export interface ThisExpression extends Node {
445445
type: 'ThisExpression'
@@ -454,6 +454,8 @@ export interface AssocExpression extends Node {
454454
properties: Property[]
455455
}
456456

457+
export type ObjectExpression = AssocExpression
458+
457459
export interface Property extends Node {
458460
type: 'Property'
459461
key: Expression

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "oscript-parser",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "A parser for the OScript language written in JavaScript.",
55
"author": "Ferdinand Prantl <[email protected]> (http://prantlf.tk/)",
66
"keywords": [
@@ -72,9 +72,9 @@
7272
"devDependencies": {
7373
"@prantlf/railroad-diagrams": "1.0.1",
7474
"@rollup/plugin-json": "4.1.0",
75-
"@types/node": "14.14.19",
76-
"@typescript-eslint/eslint-plugin": "4.11.1",
77-
"@typescript-eslint/parser": "4.11.1",
75+
"@types/node": "14.14.20",
76+
"@typescript-eslint/eslint-plugin": "4.12.0",
77+
"@typescript-eslint/parser": "4.12.0",
7878
"benchmark": "2.1.4",
7979
"chevrotain": "7.1.0",
8080
"eslint": "7.17.0",
@@ -89,7 +89,7 @@
8989
"minimatch": "3.0.4",
9090
"mkdirp": "1.0.4",
9191
"nyc": "15.1.0",
92-
"rollup": "2.35.1",
92+
"rollup": "2.36.1",
9393
"rollup-plugin-cleanup": "3.2.1",
9494
"rollup-plugin-terser": "7.0.2",
9595
"rrdiagram-js": "1.0.7",

pkg/parser/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,7 @@ function parseSwitchStatement () {
14401440
continue
14411441
}
14421442
}
1443+
if (!caseOrDefault) handleUnexpectedToken(token, 'case, default or end')
14431444
statements.push(parseStatement())
14441445
}
14451446

pkg/walker/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ base.VariableDeclarator = (node, state, walk) => {
358358

359359
base.ConditionalExpression = (node, state, walk) => {
360360
walk(node.test, node, state)
361-
for (const statement of node.consequent) walk(statement, node, state)
362-
for (const statement of node.alternate) walk(statement, node, state)
361+
walk(node.consequent, node, state)
362+
walk(node.alternate, node, state)
363363
}
364364

365365
base.BinaryExpression = (node, state, walk) => {
@@ -394,7 +394,7 @@ base.CallExpression = (node, state, walk) => {
394394

395395
base.ThisExpression = base.SuperExpression = ignore
396396

397-
base.AssocExpression = (node, state, walk) => {
397+
base.AssocExpression = base.ObjectExpression = (node, state, walk) => {
398398
for (const property of node.properties) walk(property, node, state)
399399
}
400400

pkg/walker/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "oscript-ast-walker",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "A walker for nodes of the abstract syntax tree (AST) for the OScript language.",
55
"author": "Ferdinand Prantl <[email protected]> (http://prantlf.tk/)",
66
"keywords": [

0 commit comments

Comments
 (0)