-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EmptyStatement
#2
Changes from 7 commits
e7df41a
ba9c899
c991db6
6a4834c
6546d73
a3466c8
a256802
b9b9cf3
6182029
6da8ef0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"var x = 1;\nvar y = 2" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"locals": { | ||
"x": [ | ||
{ | ||
"kind": "Var", | ||
"pos": 3 | ||
} | ||
], | ||
"y": [ | ||
{ | ||
"kind": "Var", | ||
"pos": 22 | ||
} | ||
] | ||
}, | ||
"statements": [ | ||
{ | ||
"kind": "Var", | ||
"name": { | ||
"kind": "Identifier", | ||
"text": "x" | ||
}, | ||
"typename": { | ||
"kind": "Identifier", | ||
"text": "number" | ||
}, | ||
"init": { | ||
"kind": "Literal", | ||
"value": 1 | ||
} | ||
}, | ||
{ | ||
"kind": "EmptyStatement" | ||
}, | ||
{ | ||
"kind": "Var", | ||
"name": { | ||
"kind": "Identifier", | ||
"text": "y" | ||
}, | ||
"typename": { | ||
"kind": "Identifier", | ||
"text": "number" | ||
}, | ||
"init": { | ||
"kind": "Literal", | ||
"value": 2 | ||
} | ||
}, | ||
{ | ||
"kind": "EmptyStatement" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,9 @@ | |
"kind": "Literal", | ||
"value": 2 | ||
} | ||
}, | ||
{ | ||
"kind": "EmptyStatement" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
"kind": "Identifier", | ||
"text": "x" | ||
} | ||
}, | ||
{ | ||
"kind": "EmptyStatement" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,9 @@ | |
"kind": "Literal", | ||
"value": 1 | ||
} | ||
}, | ||
{ | ||
"kind": "EmptyStatement" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ | |
"kind": "Literal", | ||
"value": 1 | ||
} | ||
}, | ||
{ | ||
"kind": "EmptyStatement" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,9 @@ | |
"value": 2 | ||
} | ||
} | ||
}, | ||
{ | ||
"kind": "EmptyStatement" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,9 @@ | |
"value": 2 | ||
} | ||
} | ||
}, | ||
{ | ||
"kind": "EmptyStatement" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,9 @@ | |
"kind": "Identifier", | ||
"text": "Net" | ||
} | ||
}, | ||
{ | ||
"kind": "EmptyStatement" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { Statement, Node, Expression } from './types'; | ||
|
||
export function emit(statements: Statement[]) { | ||
return statements.map(emitStatement).join(';\n'); | ||
return statements.filter(Boolean).map(emitStatement).join(';\n'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would personally leave the empty statements in the output, since the output should be as close as possible to the input, but with types removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense, just removed the filter imteekay/mini-typescript@6182029 |
||
} | ||
|
||
function emitStatement(statement: Statement): string { | ||
|
@@ -15,6 +15,8 @@ function emitStatement(statement: Statement): string { | |
)}`; | ||
case Node.TypeAlias: | ||
return `type ${statement.name.text} = ${statement.typename.text}`; | ||
case Node.EmptyStatement: | ||
return ''; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var x: number = 1;;var y: number = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For bonus points, see what the spec says an empty statement returns and name the type after that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the spec, it says it returns
empty
. Just renamed fromemptyType
toempty
imteekay/mini-typescript@6da8ef0 Lmk if this is what you meant for the refactoring.