update interface button styles
This commit is contained in:
1
node_modules/@lezer/javascript/.tern-port
generated
vendored
Normal file
1
node_modules/@lezer/javascript/.tern-port
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
34881
|
||||
329
node_modules/@lezer/javascript/CHANGELOG.md
generated
vendored
Normal file
329
node_modules/@lezer/javascript/CHANGELOG.md
generated
vendored
Normal file
@ -0,0 +1,329 @@
|
||||
## 1.4.4 (2023-07-03)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Add support for `using` syntax.
|
||||
|
||||
Make the package work with new TS resolution styles.
|
||||
|
||||
## 1.4.3 (2023-04-24)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Properly parse `this: Type` within parameter lists for TypeScript.
|
||||
|
||||
## 1.4.2 (2023-03-29)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Properly parse `declare` in front of class properties and methods in TypeScript.
|
||||
|
||||
## 1.4.1 (2023-01-09)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fix a bug where something like `yield [1]` (or `await`) was parsed as a member expression.
|
||||
|
||||
Add support for `yield*` syntax.
|
||||
|
||||
Escapes in strings are now parsed as their own tokens (and styled with the `escape` tag).
|
||||
|
||||
## 1.4.0 (2022-12-19)
|
||||
|
||||
### New features
|
||||
|
||||
The new `"SingleClassItem"` top-level rule can be used to parse only a class item (method, property, or static block).
|
||||
|
||||
## 1.3.2 (2022-12-14)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Typescript allows `override` on all class elements, not just methods.
|
||||
|
||||
Allow expressions in class extends clauses in TypeScript.
|
||||
|
||||
## 1.3.1 (2022-11-29)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Actually emit a tree node for the `@` characters in decorators.
|
||||
|
||||
## 1.3.0 (2022-11-28)
|
||||
|
||||
### New features
|
||||
|
||||
Add support for decorator syntax.
|
||||
|
||||
## 1.2.0 (2022-11-24)
|
||||
|
||||
### New features
|
||||
|
||||
The grammar now supports `top: "SingleExpression"` to parse an expression rather than a script.
|
||||
|
||||
## 1.1.1 (2022-11-19)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fix parsing of computed properties in class declarations.
|
||||
|
||||
## 1.1.0 (2022-11-17)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fix parsing of 'null' as type in TypeScript.
|
||||
|
||||
Allow computed properties in object destructuring patterns.
|
||||
|
||||
Add TypeScript 4.9's `satisfies` operator.
|
||||
|
||||
Support `accessor` syntax on class properties.
|
||||
|
||||
### New features
|
||||
|
||||
Add support for optional call syntax.
|
||||
|
||||
Distinguish lower-case JSX element names syntactically, give them a `standard(tagName)` highlight tag.
|
||||
|
||||
## 1.0.2 (2022-07-21)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Properly assign a highlighting tag to the `super` keyword.
|
||||
|
||||
## 1.0.1 (2022-06-27)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fix parsing of TypeScript conditional types.
|
||||
|
||||
Support type parameters in TypeScript function type syntax.
|
||||
|
||||
## 1.0.0 (2022-06-06)
|
||||
|
||||
### New features
|
||||
|
||||
First stable version.
|
||||
|
||||
## 0.16.0 (2022-04-20)
|
||||
|
||||
### Breaking changes
|
||||
|
||||
Move to 0.16 serialized parser format.
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Allow commas as separators in TypeScript object type syntax.
|
||||
|
||||
### New features
|
||||
|
||||
Add `CatchClause` and `FinallyClause` nodes wrapping parts of `TryStatement`.
|
||||
|
||||
The parser now includes syntax highlighting information in its node types.
|
||||
|
||||
## 0.15.3 (2022-01-26)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Support missing values in array pattern syntax.
|
||||
|
||||
Support quoted module export names.
|
||||
|
||||
### New features
|
||||
|
||||
Template string interpolations now get their own nodes in the syntax tree.
|
||||
|
||||
## 0.15.2 (2021-12-08)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fix a typo in the `TaggedTemplateExpression` node name. Support n suffixes after non-decimal integers
|
||||
|
||||
Add support for non-decimal bignum literals ().
|
||||
|
||||
Add support for static class initialization blocks.
|
||||
|
||||
## 0.15.1 (2021-11-12)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Add support for TypeScript `import {type X} from y` syntax.
|
||||
|
||||
Indexed TypeScript types can now take type parameters.
|
||||
|
||||
Add support for private field syntax.
|
||||
|
||||
Rename PropertyNameDefinition node to PropertyDefinition for consistency with other names.
|
||||
|
||||
### New features
|
||||
|
||||
Recognize TypeScript 4.3's `override` keyword.
|
||||
|
||||
## 0.15.0 (2021-08-11)
|
||||
|
||||
### Breaking changes
|
||||
|
||||
The module's name changed from `lezer-javascript` to `@lezer/javascript`.
|
||||
|
||||
Upgrade to the 0.15.0 lezer interfaces.
|
||||
|
||||
## 0.13.4 (2021-04-30)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fixes a bug where arrow functions with expression bodies would include commas after the expression.
|
||||
|
||||
## 0.13.3 (2021-02-15)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Wrap escaped JSX attribute values in a `JSXEscape` node.
|
||||
|
||||
## 0.13.2 (2021-01-18)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fix parsing of async function expressions.
|
||||
|
||||
## 0.13.1 (2020-12-04)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fix versions of lezer packages depended on.
|
||||
|
||||
## 0.13.0 (2020-12-04)
|
||||
|
||||
## 0.12.0 (2020-10-23)
|
||||
|
||||
### Breaking changes
|
||||
|
||||
Adjust to changed serialized parser format.
|
||||
|
||||
## 0.11.1 (2020-09-26)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fix lezer depencency versions
|
||||
|
||||
## 0.11.0 (2020-09-26)
|
||||
|
||||
### Breaking changes
|
||||
|
||||
Follow change in serialized parser format.
|
||||
|
||||
## 0.10.1 (2020-09-02)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fix associativity of `else` and ternary operators.
|
||||
|
||||
Work around accidental ambiguity of TypeScript method and constructor signatures.
|
||||
|
||||
Properly parse `??=` as an update operator.
|
||||
|
||||
## 0.10.0 (2020-08-07)
|
||||
|
||||
### Breaking changes
|
||||
|
||||
Upgrade to 0.10 parser serialization
|
||||
|
||||
### New features
|
||||
|
||||
The gammar now supports TypeScript (use the `"ts"` dialect).
|
||||
|
||||
The grammar can now parse JSX syntax (use the `"jsx"` dialect).
|
||||
|
||||
## 0.9.1 (2020-06-29)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fix accidental use of non-ES5 library methods.
|
||||
|
||||
## 0.9.0 (2020-06-08)
|
||||
|
||||
### Breaking changes
|
||||
|
||||
Upgrade to 0.9 parser serialization
|
||||
|
||||
## 0.8.4 (2020-05-30)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fix the package.json `main` field pointing at the wrong file, breaking the library in node versions older than 13.
|
||||
|
||||
## 0.8.3 (2020-04-09)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Regenerate parser with a fix in lezer-generator so that the top node prop is properly assigned.
|
||||
|
||||
## 0.8.2 (2020-04-01)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Make the package load as an ES module on node
|
||||
|
||||
## 0.8.1 (2020-02-28)
|
||||
|
||||
### New features
|
||||
|
||||
Provide an ES module file.
|
||||
|
||||
## 0.8.0 (2020-02-03)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Add support for the spread ... operator in array literals.
|
||||
|
||||
### New features
|
||||
|
||||
Follow 0.8.0 release of the library.
|
||||
|
||||
Add support for nullish coalescing and optional chaining.
|
||||
|
||||
## 0.7.0 (2020-01-20)
|
||||
|
||||
### Breaking changes
|
||||
|
||||
Use the lezer 0.7.0 parser format.
|
||||
|
||||
## 0.5.2 (2020-01-15)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Regenerate with lezer-generator 0.5.2 to avoid cyclic forced reductions.
|
||||
|
||||
## 0.5.1 (2019-10-22)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
Fix top prop missing from build output.
|
||||
|
||||
## 0.5.0 (2019-10-22)
|
||||
|
||||
### Breaking changes
|
||||
|
||||
Move from `lang` to `top` prop on document node.
|
||||
|
||||
## 0.4.0 (2019-09-10)
|
||||
|
||||
### Breaking changes
|
||||
|
||||
Adjust to 0.4.0 parse table format.
|
||||
|
||||
## 0.3.0 (2019-08-22)
|
||||
|
||||
### New features
|
||||
|
||||
Go back to node names, add props, follow changes in grammar syntax.
|
||||
|
||||
## 0.2.0 (2019-08-02)
|
||||
|
||||
### New features
|
||||
|
||||
Use tags rather than names.
|
||||
|
||||
## 0.1.0 (2019-07-09)
|
||||
|
||||
### New Features
|
||||
|
||||
First documented release.
|
||||
21
node_modules/@lezer/javascript/LICENSE
generated
vendored
Normal file
21
node_modules/@lezer/javascript/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (C) 2018 by Marijn Haverbeke <marijn@haverbeke.berlin> and others
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
14
node_modules/@lezer/javascript/README.md
generated
vendored
Normal file
14
node_modules/@lezer/javascript/README.md
generated
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
# @lezer/javascript
|
||||
|
||||
This is a JavaScript grammar for the
|
||||
[lezer](https://lezer.codemirror.net/) parser system.
|
||||
|
||||
It parses ES2020, and supports a `"ts"`
|
||||
[dialect](https://lezer.codemirror.net/docs/guide/#dialects) to parse
|
||||
TypeScript, and a `"jsx"` dialect to parse JSX.
|
||||
|
||||
The `top` option can be set to `"SingleExpression"` or
|
||||
`"SingleClassItem"` to parse an expression or class item instead of a
|
||||
full program.
|
||||
|
||||
The code is licensed under an MIT license.
|
||||
149
node_modules/@lezer/javascript/dist/index.cjs
generated
vendored
Normal file
149
node_modules/@lezer/javascript/dist/index.cjs
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
3
node_modules/@lezer/javascript/dist/index.d.cts
generated
vendored
Normal file
3
node_modules/@lezer/javascript/dist/index.d.cts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import {LRParser} from "@lezer/lr"
|
||||
|
||||
export const parser: LRParser
|
||||
3
node_modules/@lezer/javascript/dist/index.d.ts
generated
vendored
Normal file
3
node_modules/@lezer/javascript/dist/index.d.ts
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import {LRParser} from "@lezer/lr"
|
||||
|
||||
export const parser: LRParser
|
||||
145
node_modules/@lezer/javascript/dist/index.js
generated
vendored
Normal file
145
node_modules/@lezer/javascript/dist/index.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
35
node_modules/@lezer/javascript/package.json
generated
vendored
Normal file
35
node_modules/@lezer/javascript/package.json
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "@lezer/javascript",
|
||||
"version": "1.4.4",
|
||||
"description": "lezer-based JavaScript grammar",
|
||||
"main": "dist/index.cjs",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"module": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"author": "Marijn Haverbeke <marijn@haverbeke.berlin>",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@lezer/generator": "^1.0.0",
|
||||
"mocha": "^9.0.1",
|
||||
"rollup": "^2.52.2",
|
||||
"@rollup/plugin-node-resolve": "^9.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lezer/lr": "^1.3.0",
|
||||
"@lezer/highlight": "^1.1.3"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/lezer-parser/javascript.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "lezer-generator src/javascript.grammar -o src/parser && rollup -c",
|
||||
"build-debug": "lezer-generator src/javascript.grammar --names -o src/parser && rollup -c",
|
||||
"prepare": "npm run build",
|
||||
"test": "mocha test/test-*.js"
|
||||
}
|
||||
}
|
||||
16
node_modules/@lezer/javascript/rollup.config.js
generated
vendored
Normal file
16
node_modules/@lezer/javascript/rollup.config.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
import {nodeResolve} from "@rollup/plugin-node-resolve"
|
||||
|
||||
export default {
|
||||
input: "./src/parser.js",
|
||||
output: [{
|
||||
format: "cjs",
|
||||
file: "./dist/index.cjs"
|
||||
}, {
|
||||
format: "es",
|
||||
file: "./dist/index.js"
|
||||
}],
|
||||
external(id) { return !/^[\.\/]/.test(id) },
|
||||
plugins: [
|
||||
nodeResolve()
|
||||
]
|
||||
}
|
||||
61
node_modules/@lezer/javascript/src/highlight.js
generated
vendored
Normal file
61
node_modules/@lezer/javascript/src/highlight.js
generated
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
import {styleTags, tags as t} from "@lezer/highlight"
|
||||
|
||||
export const jsHighlight = styleTags({
|
||||
"get set async static": t.modifier,
|
||||
"for while do if else switch try catch finally return throw break continue default case": t.controlKeyword,
|
||||
"in of await yield void typeof delete instanceof": t.operatorKeyword,
|
||||
"let var const function class extends": t.definitionKeyword,
|
||||
"import export from": t.moduleKeyword,
|
||||
"with debugger as new": t.keyword,
|
||||
TemplateString: t.special(t.string),
|
||||
super: t.atom,
|
||||
BooleanLiteral: t.bool,
|
||||
this: t.self,
|
||||
null: t.null,
|
||||
Star: t.modifier,
|
||||
VariableName: t.variableName,
|
||||
"CallExpression/VariableName TaggedTemplateExpression/VariableName": t.function(t.variableName),
|
||||
VariableDefinition: t.definition(t.variableName),
|
||||
Label: t.labelName,
|
||||
PropertyName: t.propertyName,
|
||||
PrivatePropertyName: t.special(t.propertyName),
|
||||
"CallExpression/MemberExpression/PropertyName": t.function(t.propertyName),
|
||||
"FunctionDeclaration/VariableDefinition": t.function(t.definition(t.variableName)),
|
||||
"ClassDeclaration/VariableDefinition": t.definition(t.className),
|
||||
PropertyDefinition: t.definition(t.propertyName),
|
||||
PrivatePropertyDefinition: t.definition(t.special(t.propertyName)),
|
||||
UpdateOp: t.updateOperator,
|
||||
LineComment: t.lineComment,
|
||||
BlockComment: t.blockComment,
|
||||
Number: t.number,
|
||||
String: t.string,
|
||||
Escape: t.escape,
|
||||
ArithOp: t.arithmeticOperator,
|
||||
LogicOp: t.logicOperator,
|
||||
BitOp: t.bitwiseOperator,
|
||||
CompareOp: t.compareOperator,
|
||||
RegExp: t.regexp,
|
||||
Equals: t.definitionOperator,
|
||||
Arrow: t.function(t.punctuation),
|
||||
": Spread": t.punctuation,
|
||||
"( )": t.paren,
|
||||
"[ ]": t.squareBracket,
|
||||
"{ }": t.brace,
|
||||
"InterpolationStart InterpolationEnd": t.special(t.brace),
|
||||
".": t.derefOperator,
|
||||
", ;": t.separator,
|
||||
"@": t.meta,
|
||||
|
||||
TypeName: t.typeName,
|
||||
TypeDefinition: t.definition(t.typeName),
|
||||
"type enum interface implements namespace module declare": t.definitionKeyword,
|
||||
"abstract global Privacy readonly override": t.modifier,
|
||||
"is keyof unique infer": t.operatorKeyword,
|
||||
|
||||
JSXAttributeValue: t.attributeValue,
|
||||
JSXText: t.content,
|
||||
"JSXStartTag JSXStartCloseTag JSXSelfCloseEndTag JSXEndTag": t.angleBracket,
|
||||
"JSXIdentifier JSXNameSpacedName": t.tagName,
|
||||
"JSXAttribute/JSXIdentifier JSXAttribute/JSXNameSpacedName": t.attributeName,
|
||||
"JSXBuiltin/JSXIdentifier": t.standard(t.tagName)
|
||||
})
|
||||
701
node_modules/@lezer/javascript/src/javascript.grammar
generated
vendored
Normal file
701
node_modules/@lezer/javascript/src/javascript.grammar
generated
vendored
Normal file
@ -0,0 +1,701 @@
|
||||
@dialects { jsx, ts }
|
||||
|
||||
@precedence {
|
||||
typeargs,
|
||||
typeMember,
|
||||
typePrefix,
|
||||
intersection @left,
|
||||
union @left,
|
||||
typeExtends @right,
|
||||
else @right,
|
||||
member,
|
||||
readonly,
|
||||
newArgs,
|
||||
call,
|
||||
taggedTemplate,
|
||||
prefix,
|
||||
postfix,
|
||||
typeof,
|
||||
exp @left,
|
||||
times @left,
|
||||
plus @left,
|
||||
shift @left,
|
||||
loop,
|
||||
rel @left,
|
||||
satisfies,
|
||||
equal @left,
|
||||
bitOr @left,
|
||||
bitXor @left,
|
||||
bitAnd @left,
|
||||
and @left,
|
||||
or @left,
|
||||
ternary @right,
|
||||
assign @right,
|
||||
comma @left,
|
||||
statement @cut,
|
||||
predicate
|
||||
}
|
||||
|
||||
@top Script { statement+ }
|
||||
|
||||
@top SingleExpression { expression }
|
||||
|
||||
@top SingleClassItem { classItem }
|
||||
|
||||
statement[@isGroup=Statement] {
|
||||
ExportDeclaration |
|
||||
ImportDeclaration |
|
||||
ForStatement { kw<"for"> ckw<"await">? (ForSpec | ForInSpec | ForOfSpec) statement } |
|
||||
WhileStatement { kw<"while"> ParenthesizedExpression statement } |
|
||||
WithStatement { kw<"with"> ParenthesizedExpression statement } |
|
||||
DoStatement { kw<"do"> statement kw<"while"> ParenthesizedExpression semi } |
|
||||
IfStatement { kw<"if"> ParenthesizedExpression statement (!else kw<"else"> statement)? } |
|
||||
SwitchStatement { kw<"switch"> ParenthesizedExpression SwitchBody { "{" switchItem* "}" } } |
|
||||
TryStatement {
|
||||
kw<"try"> Block
|
||||
CatchClause { kw<"catch"> ("(" pattern ")")? Block }?
|
||||
FinallyClause { kw<"finally"> Block }?
|
||||
} |
|
||||
ReturnStatement { kw<"return"> (noSemi expression)? semi } |
|
||||
ThrowStatement { kw<"throw"> expression semi } |
|
||||
BreakStatement { kw<"break"> (noSemi Label)? semi } |
|
||||
ContinueStatement { kw<"continue"> (noSemi Label)? semi } |
|
||||
DebuggerStatement { kw<"debugger"> semi } |
|
||||
Block |
|
||||
LabeledStatement { Label ":" statement } |
|
||||
declaration |
|
||||
ExpressionStatement { expression semi } |
|
||||
";"
|
||||
}
|
||||
|
||||
ExportDeclaration {
|
||||
kw<"export"> Star (ckw<"as"> (VariableName | String))? ckw<"from"> String semi |
|
||||
kw<"export"> kw<"default"> (FunctionDeclaration | ClassDeclaration | expression semi) |
|
||||
kw<"export"> tskw<"type">? declaration |
|
||||
kw<"export"> tskw<"type">? ExportGroup (ckw<"from"> String)? semi |
|
||||
kw<"export"> "=" expression semi
|
||||
}
|
||||
|
||||
ExportGroup {
|
||||
"{" commaSep<VariableName (ckw<"as"> (VariableName { word } | String))?> "}"
|
||||
}
|
||||
|
||||
ImportDeclaration {
|
||||
kw<"import"> tskw<"type">? (Star ckw<"as"> VariableDefinition | commaSep<VariableDefinition | ImportGroup>)
|
||||
ckw<"from"> String semi |
|
||||
kw<"import"> String semi
|
||||
}
|
||||
|
||||
ImportGroup {
|
||||
"{" commaSep<tskw<"type">? (VariableDefinition | (VariableName | String) ckw<"as"> VariableDefinition)> "}"
|
||||
}
|
||||
|
||||
ForSpec {
|
||||
"("
|
||||
(VariableDeclaration | expression ";" | ";") expression? ";" expression?
|
||||
")"
|
||||
}
|
||||
|
||||
forXSpec<op> {
|
||||
"("
|
||||
(variableDeclarationKeyword pattern | VariableName | MemberExpression | ArrayPattern | ObjectPattern)
|
||||
!loop op expression
|
||||
")"
|
||||
}
|
||||
|
||||
ForInSpec { forXSpec<kw<"in">> }
|
||||
ForOfSpec { forXSpec<ckw<"of">> }
|
||||
|
||||
declaration {
|
||||
FunctionDeclaration |
|
||||
ClassDeclaration |
|
||||
VariableDeclaration |
|
||||
TypeAliasDeclaration |
|
||||
InterfaceDeclaration |
|
||||
EnumDeclaration |
|
||||
NamespaceDeclaration |
|
||||
AmbientDeclaration
|
||||
}
|
||||
|
||||
FunctionDeclaration {
|
||||
async? !statement kw<"function"> Star? VariableDefinition? functionSignature (Block | semi)
|
||||
}
|
||||
|
||||
ClassDeclaration {
|
||||
!statement Decorator* tskw<"abstract">? kw<"class"> VariableDefinition TypeParamList?
|
||||
(kw<"extends"> ((VariableName | MemberExpression) !typeargs TypeArgList | expression))?
|
||||
(tskw<"implements"> commaSep1<type>)?
|
||||
ClassBody
|
||||
}
|
||||
|
||||
classItem { MethodDeclaration | PropertyDeclaration | StaticBlock | ";" }
|
||||
|
||||
ClassBody { "{" classItem* "}" }
|
||||
|
||||
privacy {
|
||||
@extend[@name=Privacy,@dialect=ts]<word, "public" | "private" | "protected">
|
||||
}
|
||||
|
||||
privacyArg {
|
||||
@extend[@name=Privacy,@dialect=ts]<identifier, "public" | "private" | "protected">
|
||||
}
|
||||
|
||||
propModifier {
|
||||
Decorator |
|
||||
tsPkwMod<"declare"> |
|
||||
privacy |
|
||||
pkwMod<"static"> |
|
||||
tsPkwMod<"abstract"> |
|
||||
tsPkwMod<"override">
|
||||
}
|
||||
|
||||
MethodDeclaration[group=ClassItem] {
|
||||
propModifier*
|
||||
pkwMod<"async">?
|
||||
(pkwMod<"get"> | pkwMod<"set"> | Star)?
|
||||
(propName | PrivatePropertyDefinition)
|
||||
functionSignature
|
||||
(Block | semi)
|
||||
}
|
||||
|
||||
StaticBlock[group=ClassItem] {
|
||||
pkwMod<"static"> Block
|
||||
}
|
||||
|
||||
PropertyDeclaration[group=ClassItem] {
|
||||
propModifier*
|
||||
(tsPkwMod<"readonly"> | pkwMod<"accessor">)?
|
||||
(propName | PrivatePropertyDefinition)
|
||||
(Optional | LogicOp<"!">)?
|
||||
TypeAnnotation?
|
||||
("=" expressionNoComma)?
|
||||
semi
|
||||
}
|
||||
|
||||
variableDeclarationKeyword {
|
||||
kw<"let"> | kw<"var"> | kw<"const"> | ckw<"await">? ckw<"using">
|
||||
}
|
||||
|
||||
VariableDeclaration {
|
||||
variableDeclarationKeyword commaSep1<patternAssignTyped> semi
|
||||
}
|
||||
|
||||
TypeAliasDeclaration {
|
||||
tskw<"type"> TypeDefinition TypeParamList? "=" type semi
|
||||
}
|
||||
|
||||
InterfaceDeclaration {
|
||||
tskw<"interface"> TypeDefinition TypeParamList? (kw<"extends"> type)? ObjectType
|
||||
}
|
||||
|
||||
EnumDeclaration {
|
||||
kw<"const">? tskw<"enum"> TypeDefinition EnumBody { "{" commaSep<PropertyName ("=" expressionNoComma)?> "}" }
|
||||
}
|
||||
|
||||
NamespaceDeclaration {
|
||||
(tskw<"namespace"> | tskw<"module">) VariableDefinition ("." PropertyDefinition)* Block
|
||||
}
|
||||
|
||||
AmbientDeclaration {
|
||||
tskw<"declare"> (
|
||||
VariableDeclaration |
|
||||
TypeAliasDeclaration |
|
||||
EnumDeclaration |
|
||||
InterfaceDeclaration |
|
||||
NamespaceDeclaration |
|
||||
GlobalDeclaration { tskw<"global"> Block } |
|
||||
ClassDeclaration {
|
||||
tskw<"abstract">? kw<"class"> VariableDefinition TypeParamList?
|
||||
(kw<"extends"> expression)?
|
||||
(tskw<"implements"> commaSep1<type>)?
|
||||
ClassBody { "{" (
|
||||
MethodDeclaration |
|
||||
PropertyDeclaration |
|
||||
IndexSignature semi
|
||||
)* "}" }
|
||||
} |
|
||||
AmbientFunctionDeclaration {
|
||||
async? kw<"function"> Star? VariableDefinition? TypeParamList? ParamList (TypeAnnotation | TypePredicate) semi
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
decoratorExpression {
|
||||
VariableName |
|
||||
MemberExpression { decoratorExpression !member ("." | "?.") (PropertyName | PrivatePropertyName) } |
|
||||
CallExpression { decoratorExpression !call TypeArgList? "?."? ArgList } |
|
||||
ParenthesizedExpression
|
||||
}
|
||||
|
||||
Decorator { "@" decoratorExpression }
|
||||
|
||||
pattern { VariableDefinition | ArrayPattern | ObjectPattern }
|
||||
|
||||
ArrayPattern { "[" commaSep<("..."? patternAssign)?> ~destructure "]" }
|
||||
|
||||
ObjectPattern { "{" commaSep<PatternProperty> ~destructure "}" }
|
||||
|
||||
patternAssign {
|
||||
pattern ("=" expressionNoComma)?
|
||||
}
|
||||
|
||||
TypeAnnotation { ":" type }
|
||||
|
||||
TypePredicate { ":" (VariableName | kw<"this">) !predicate tskw<"is"> type }
|
||||
|
||||
patternAssignTyped {
|
||||
pattern Optional? TypeAnnotation? ("=" expressionNoComma)?
|
||||
}
|
||||
|
||||
ParamList {
|
||||
"(" commaSep<"..." patternAssignTyped | Decorator* privacyArg? tskw<"readonly">? patternAssignTyped | kw<"this"> TypeAnnotation> ")"
|
||||
}
|
||||
|
||||
Block {
|
||||
!statement "{" statement* "}"
|
||||
}
|
||||
|
||||
switchItem {
|
||||
CaseLabel { kw<"case"> expression ":" } |
|
||||
DefaultLabel { kw<"default"> ":" } |
|
||||
statement
|
||||
}
|
||||
|
||||
expression[@isGroup=Expression] {
|
||||
expressionNoComma | SequenceExpression
|
||||
}
|
||||
|
||||
SequenceExpression {
|
||||
expressionNoComma !comma ("," expressionNoComma)+
|
||||
}
|
||||
|
||||
expressionNoComma {
|
||||
Number |
|
||||
String |
|
||||
TemplateString |
|
||||
VariableName |
|
||||
boolean |
|
||||
kw<"this"> |
|
||||
kw<"null"> |
|
||||
kw<"super"> |
|
||||
RegExp |
|
||||
ArrayExpression |
|
||||
ObjectExpression { "{" commaSep<Property> ~destructure "}" } |
|
||||
NewExpression { kw<"new"> expressionNoComma (!newArgs TypeArgList? ArgList)? } |
|
||||
UnaryExpression |
|
||||
YieldExpression |
|
||||
AwaitExpression |
|
||||
ParenthesizedExpression |
|
||||
ClassExpression |
|
||||
FunctionExpression |
|
||||
ArrowFunction |
|
||||
MemberExpression |
|
||||
BinaryExpression |
|
||||
ConditionalExpression { expressionNoComma !ternary questionOp expressionNoComma LogicOp<":"> expressionNoComma } |
|
||||
AssignmentExpression |
|
||||
PostfixExpression { expressionNoComma !postfix (incdec | LogicOp<"!">) } |
|
||||
CallExpression { expressionNoComma !call TypeArgList? "?."? ArgList } |
|
||||
TaggedTemplateExpression { expressionNoComma !taggedTemplate TemplateString } |
|
||||
DynamicImport { kw<"import"> "(" expressionNoComma ")" } |
|
||||
ImportMeta { kw<"import"> "." PropertyName } |
|
||||
JSXElement |
|
||||
PrefixCast { tsAngleOpen type ~tsAngle ">" expressionNoComma } |
|
||||
ArrowFunction[@dynamicPrecedence=1] {
|
||||
TypeParamList { tsAngleOpen commaSep<typeParam> ">" } ParamList TypeAnnotation? "=>" (Block | expressionNoComma)
|
||||
}
|
||||
}
|
||||
|
||||
ParenthesizedExpression { "(" expression ")" }
|
||||
|
||||
ArrayExpression {
|
||||
"[" commaSep1<"..."? expressionNoComma | ""> ~destructure "]"
|
||||
}
|
||||
|
||||
propName { PropertyDefinition | "[" expression "]" | Number | String }
|
||||
|
||||
Property {
|
||||
pkwMod<"async">? (pkwMod<"get"> | pkwMod<"set"> | Star)? propName functionSignature Block |
|
||||
propName ~destructure (":" expressionNoComma)? |
|
||||
"..." expressionNoComma
|
||||
}
|
||||
|
||||
PatternProperty {
|
||||
"..." patternAssign |
|
||||
((PropertyName | Number | String) ~destructure (":" pattern)? |
|
||||
("[" expression "]" ~destructure ":" pattern)) ("=" expressionNoComma)?
|
||||
}
|
||||
|
||||
ClassExpression {
|
||||
kw<"class"> VariableDefinition? (kw<"extends"> expression)? ClassBody
|
||||
}
|
||||
|
||||
functionSignature { TypeParamList? ParamList (TypeAnnotation | TypePredicate)? }
|
||||
|
||||
FunctionExpression {
|
||||
async? kw<"function"> Star? VariableDefinition? functionSignature Block
|
||||
}
|
||||
|
||||
YieldExpression[@dynamicPrecedence=1] {
|
||||
!prefix ckw<"yield"> Star? expressionNoComma
|
||||
}
|
||||
|
||||
AwaitExpression[@dynamicPrecedence=1] {
|
||||
!prefix ckw<"await"> expressionNoComma
|
||||
}
|
||||
|
||||
UnaryExpression {
|
||||
!prefix (kw<"void"> | kw<"typeof"> | kw<"delete"> |
|
||||
LogicOp<"!"> | BitOp<"~"> | incdec | incdecPrefix | ArithOp<"+" | "-">)
|
||||
expressionNoComma
|
||||
}
|
||||
|
||||
BinaryExpression {
|
||||
expressionNoComma !exp ArithOp<"**"> expressionNoComma |
|
||||
expressionNoComma !times (divide | ArithOp<"%"> | ArithOp<"*">) expressionNoComma |
|
||||
expressionNoComma !plus ArithOp<"+" | "-"> expressionNoComma |
|
||||
expressionNoComma !shift BitOp<">>" ">"? | "<<"> expressionNoComma |
|
||||
expressionNoComma !rel (LessThan | CompareOp<"<=" | ">" "="?> | kw<"instanceof">) expressionNoComma |
|
||||
expressionNoComma !satisfies tskw<"satisfies"> type |
|
||||
(expressionNoComma | PrivatePropertyName) !rel ~tsIn kw<"in"> expressionNoComma |
|
||||
expressionNoComma !rel ckw<"as"> (kw<"const"> | type) |
|
||||
expressionNoComma !equal CompareOp<"==" "="? | "!=" "="?> expressionNoComma |
|
||||
expressionNoComma !bitOr BitOp { "|" } expressionNoComma |
|
||||
expressionNoComma !bitXor BitOp<"^"> expressionNoComma |
|
||||
expressionNoComma !bitAnd BitOp { "&" } expressionNoComma |
|
||||
expressionNoComma !and LogicOp<"&&"> expressionNoComma |
|
||||
expressionNoComma !or LogicOp<"||" | "??"> expressionNoComma
|
||||
}
|
||||
|
||||
AssignmentExpression {
|
||||
(VariableName | MemberExpression) !assign UpdateOp<($[+\-/%^] | "*" "*"? | "|" "|"? | "&" "&"? | "<<" | ">>" ">"? | "??") "=">
|
||||
expressionNoComma |
|
||||
(VariableName | MemberExpression | ArrayPattern | ObjectPattern) !assign "=" expressionNoComma
|
||||
}
|
||||
|
||||
MemberExpression {
|
||||
expressionNoComma !member (("." | "?.") (PropertyName | PrivatePropertyName) | "?."? "[" expression "]")
|
||||
}
|
||||
|
||||
ArgList {
|
||||
"(" commaSep<"..."? expressionNoComma> ")"
|
||||
}
|
||||
|
||||
ArrowFunction {
|
||||
async? (ParamList { VariableDefinition } | ParamList TypeAnnotation?) "=>" (Block | expressionNoComma)
|
||||
}
|
||||
|
||||
TypeArgList {
|
||||
@extend[@dialect=ts,@name="<"]<LessThan, "<"> commaSep<type> ">"
|
||||
}
|
||||
|
||||
TypeParamList {
|
||||
"<" commaSep<typeParam> ">"
|
||||
}
|
||||
|
||||
typeParam { TypeDefinition ~tsAngle (kw<"extends"> type)? ("=" type)? }
|
||||
|
||||
typeofMemberExpression[@name=MemberExpression] {
|
||||
VariableName !member (("." | "?.") PropertyName | "[" expression "]")
|
||||
}
|
||||
|
||||
type[@isGroup=Type] {
|
||||
ThisType { kw<"this"> } |
|
||||
LiteralType {
|
||||
ArithOp<"+" | "-">? Number |
|
||||
boolean |
|
||||
String
|
||||
} |
|
||||
TemplateType |
|
||||
NullType { kw<"null"> } |
|
||||
VoidType { kw<"void"> } |
|
||||
TypeofType { kw<"typeof"> (VariableName | typeofMemberExpression) } |
|
||||
KeyofType { !typePrefix tskw<"keyof"> type } |
|
||||
UniqueType { !typePrefix tskw<"unique"> type } |
|
||||
ImportType { kw<"import"> "(" String ")" } |
|
||||
InferredType { tskw<"infer"> TypeName } |
|
||||
ParenthesizedType { "(" type ")" } |
|
||||
FunctionSignature { TypeParamList? ParamTypeList "=>" type } |
|
||||
NewSignature { kw<"new"> ParamTypeList "=>" type } |
|
||||
IndexedType |
|
||||
TupleType { "[" commaSep<(Label ":")? type | "..." type> "]" } |
|
||||
ArrayType { type "[" "]" | type "[" "]" } |
|
||||
ReadonlyType { tskw<"readonly"> !readonly type } |
|
||||
ObjectType |
|
||||
UnionType { type !union LogicOp { "|" } type } |
|
||||
IntersectionType { type !intersection LogicOp { "&" } type } |
|
||||
ConditionalType { type !typeExtends kw<"extends"> type questionOp ~arrow type LogicOp<":"> type } |
|
||||
ParameterizedType { (TypeName | IndexedType) !typeargs TypeArgList } |
|
||||
TypeName
|
||||
}
|
||||
|
||||
IndexedType {
|
||||
type !typeMember ("." TypeName | "[" (String | Number) "]")+
|
||||
}
|
||||
|
||||
ObjectType {
|
||||
"{" (
|
||||
(MethodType |
|
||||
PropertyType |
|
||||
IndexSignature |
|
||||
CallSignature { ParamTypeList (TypeAnnotation | TypePredicate) } |
|
||||
NewSignature[@dynamicPrecedence=1] { @extend[@name=new]<word, "new"> ParamTypeList TypeAnnotation })
|
||||
("," | semi)
|
||||
)* "}"
|
||||
}
|
||||
|
||||
IndexSignature {
|
||||
tsPkwMod<"readonly">? "[" PropertyDefinition { identifier } (TypeAnnotation | ~tsIn kw<"in"> type) "]" TypeAnnotation
|
||||
}
|
||||
|
||||
MethodType {
|
||||
pkwMod<"async">?
|
||||
(pkwMod<"get"> | pkwMod<"set"> | Star)?
|
||||
PropertyDefinition
|
||||
functionSignature
|
||||
}
|
||||
|
||||
PropertyType {
|
||||
(ArithOp<"+" | "-">? tsPkwMod<"readonly">)?
|
||||
PropertyDefinition
|
||||
(ArithOp<"+" | "-">? Optional)?
|
||||
TypeAnnotation
|
||||
}
|
||||
|
||||
ParamTypeList[@name=ParamList] {
|
||||
"(" commaSep<"..."? VariableDefinition ~arrow Optional? ~arrow TypeAnnotation?> ")"
|
||||
}
|
||||
|
||||
@skip {} {
|
||||
TemplateString {
|
||||
templateStart (templateEscape | templateContent | templateExpr)* templateEnd
|
||||
}
|
||||
|
||||
TemplateType {
|
||||
templateStart (templateContent | templateType)* templateEnd
|
||||
}
|
||||
|
||||
String {
|
||||
'"' (stringContentDouble | Escape)* ('"' | "\n") |
|
||||
"'" (stringContentSingle | Escape)* ("'" | "\n")
|
||||
}
|
||||
|
||||
BlockComment { "/*" (blockCommentContent | blockCommentNewline)* blockCommentEnd }
|
||||
}
|
||||
|
||||
templateExpr[@name=Interpolation] { InterpolationStart expression InterpolationEnd }
|
||||
|
||||
templateType[@name=Interpolation] { InterpolationStart type InterpolationEnd }
|
||||
|
||||
@skip {} {
|
||||
JSXElement {
|
||||
JSXSelfClosingTag |
|
||||
(JSXOpenTag | JSXFragmentTag) (JSXText | JSXElement | JSXEscape)* JSXCloseTag
|
||||
}
|
||||
}
|
||||
|
||||
JSXSelfClosingTag { JSXStartTag jsxElementName jsxAttribute* JSXSelfCloseEndTag }
|
||||
|
||||
JSXOpenTag { JSXStartTag jsxElementName jsxAttribute* JSXEndTag }
|
||||
|
||||
JSXFragmentTag { JSXStartTag JSXEndTag }
|
||||
|
||||
JSXCloseTag { JSXStartCloseTag jsxElementName? JSXEndTag }
|
||||
|
||||
jsxElementName {
|
||||
JSXIdentifier |
|
||||
JSXBuiltin { JSXLowerIdentifier } |
|
||||
JSXNamespacedName |
|
||||
JSXMemberExpression
|
||||
}
|
||||
|
||||
JSXMemberExpression { (JSXMemberExpression | JSXIdentifier | JSXLowerIdentifier) "." (JSXIdentifier | JSXLowerIdentifier) }
|
||||
|
||||
JSXNamespacedName { (JSXIdentifier | JSXNamespacedName | JSXLowerIdentifier) ":" (JSXIdentifier | JSXLowerIdentifier) }
|
||||
|
||||
jsxAttribute {
|
||||
JSXSpreadAttribute { "{" "..." expression "}" } |
|
||||
JSXAttribute { (JSXIdentifier | JSXNamespacedName | JSXLowerIdentifier) ("=" jsxAttributeValue)? }
|
||||
}
|
||||
|
||||
jsxAttributeValue {
|
||||
JSXAttributeValue |
|
||||
JSXEscape { "{" expression "}" } |
|
||||
JSXElement
|
||||
}
|
||||
|
||||
JSXEscape { "{" "..."? expression "}" }
|
||||
|
||||
commaSep<content> {
|
||||
"" | content ("," content?)*
|
||||
}
|
||||
|
||||
commaSep1<content> {
|
||||
content ("," content)*
|
||||
}
|
||||
|
||||
// Keywords
|
||||
|
||||
kw<term> { @specialize[@name={term}]<identifier, term> }
|
||||
|
||||
// Contextual keywords
|
||||
|
||||
ckw<term> { @extend[@name={term}]<identifier, term> }
|
||||
|
||||
tskw<term> { @extend[@name={term},@dialect=ts]<identifier, term> }
|
||||
|
||||
async { @extend[@name=async]<identifier, "async"> }
|
||||
|
||||
// Contextual keyword in property context
|
||||
|
||||
pkwMod<term> { @extend[@name={term}]<word, term> }
|
||||
|
||||
tsPkwMod<term> { @extend[@name={term},@dialect=ts]<word, term> }
|
||||
|
||||
semi { ";" | insertSemi }
|
||||
|
||||
boolean { @specialize[@name=BooleanLiteral]<identifier, "true" | "false"> }
|
||||
|
||||
Star { "*" }
|
||||
|
||||
VariableName { identifier ~arrow }
|
||||
|
||||
VariableDefinition { identifier ~arrow }
|
||||
|
||||
TypeDefinition { identifier }
|
||||
|
||||
TypeName { identifier ~arrow }
|
||||
|
||||
Label { identifier }
|
||||
|
||||
PropertyName { word }
|
||||
|
||||
PropertyDefinition { word }
|
||||
|
||||
PrivatePropertyName { privateIdentifier }
|
||||
|
||||
PrivatePropertyDefinition { privateIdentifier }
|
||||
|
||||
Optional { "?" }
|
||||
|
||||
questionOp[@name=LogicOp] { "?" }
|
||||
|
||||
@skip { spaces | newline | LineComment | BlockComment }
|
||||
|
||||
@context trackNewline from "./tokens.js"
|
||||
|
||||
@external tokens noSemicolon from "./tokens" { noSemi }
|
||||
|
||||
@external tokens incdecToken from "./tokens" {
|
||||
incdec[@name=ArithOp],
|
||||
incdecPrefix[@name=ArithOp]
|
||||
}
|
||||
|
||||
@local tokens {
|
||||
InterpolationStart[closedBy=InterpolationEnd] { "${" }
|
||||
templateEnd { "`" }
|
||||
templateEscape[@name=Escape] { Escape }
|
||||
@else templateContent
|
||||
}
|
||||
|
||||
@local tokens {
|
||||
blockCommentEnd { "*/" }
|
||||
blockCommentNewline { "\n" }
|
||||
@else blockCommentContent
|
||||
}
|
||||
|
||||
@tokens {
|
||||
spaces[@export] { $[\u0009 \u000b\u00a0\u1680\u2000-\u200a\u202f\u205f\u3000\ufeff]+ }
|
||||
newline[@export] { $[\r\n\u2028\u2029] }
|
||||
|
||||
LineComment { "//" ![\n]* }
|
||||
|
||||
divide[@name=ArithOp] { "/" }
|
||||
|
||||
@precedence { "/*", LineComment, divide }
|
||||
|
||||
@precedence { "/*", LineComment, RegExp }
|
||||
|
||||
identifierChar { @asciiLetter | $[_$\u{a1}-\u{10ffff}] }
|
||||
|
||||
word { identifierChar (identifierChar | @digit)* }
|
||||
|
||||
identifier { word }
|
||||
|
||||
privateIdentifier { "#" word }
|
||||
|
||||
@precedence { spaces, newline, identifier }
|
||||
|
||||
@precedence { spaces, newline, JSXIdentifier, JSXLowerIdentifier }
|
||||
|
||||
@precedence { spaces, newline, word }
|
||||
|
||||
hex { @digit | $[a-fA-F] }
|
||||
|
||||
Number {
|
||||
(@digit ("_" | @digit)* ("." ("_" | @digit)*)? | "." @digit ("_" | @digit)*)
|
||||
(("e" | "E") ("+" | "-")? ("_" | @digit)+)? |
|
||||
@digit ("_" | @digit)* "n" |
|
||||
"0x" (hex | "_")+ "n"? |
|
||||
"0b" $[01_]+ "n"? |
|
||||
"0o" $[0-7_]+ "n"?
|
||||
}
|
||||
|
||||
@precedence { Number "." }
|
||||
|
||||
Escape {
|
||||
"\\" ("x" hex hex | "u" ("{" hex+ "}" | hex hex hex hex) | ![xu])
|
||||
}
|
||||
|
||||
stringContentSingle { ![\\\n']+ }
|
||||
|
||||
stringContentDouble { ![\\\n"]+ }
|
||||
|
||||
templateStart { "`" }
|
||||
|
||||
InterpolationEnd[openedBy=InterpolationStart] { "}" }
|
||||
|
||||
ArithOp<expr> { expr }
|
||||
LogicOp<expr> { expr }
|
||||
BitOp<expr> { expr }
|
||||
CompareOp<expr> { expr }
|
||||
UpdateOp<expr> { expr }
|
||||
|
||||
@precedence { "*", ArithOp }
|
||||
|
||||
RegExp { "/" (![/\\\n[] | "\\" ![\n] | "[" (![\n\\\]] | "\\" ![\n])* "]")+ ("/" $[gimsuy]*)? }
|
||||
|
||||
LessThan[@name=CompareOp] { "<" }
|
||||
|
||||
"="[@name=Equals]
|
||||
"..."[@name=Spread]
|
||||
"=>"[@name=Arrow]
|
||||
|
||||
"(" ")" "[" "]" "{" "}" ">"
|
||||
|
||||
"?." "." "," ";" ":" "@"
|
||||
|
||||
JSXIdentifier { $[A-Z_$\u{a1}-\u{10ffff}] (identifierChar | @digit | "-")* }
|
||||
JSXLowerIdentifier[@name=JSXIdentifier] { $[a-z] (identifierChar | @digit | "-")* }
|
||||
|
||||
JSXAttributeValue { '"' !["]* '"' | "'" ![']* "'" }
|
||||
|
||||
JSXStartTag[@dialect=jsx] { "<" }
|
||||
|
||||
JSXStartCloseTag { "</" }
|
||||
|
||||
JSXEndTag { ">" }
|
||||
|
||||
JSXSelfCloseEndTag { "/>" }
|
||||
|
||||
JSXText { ![<{]+ }
|
||||
|
||||
tsAngleOpen[@dialect=ts] { "<" }
|
||||
|
||||
@precedence { JSXStartTag, tsAngleOpen }
|
||||
}
|
||||
|
||||
@external tokens insertSemicolon from "./tokens" { insertSemi }
|
||||
|
||||
@external propSource jsHighlight from "./highlight"
|
||||
|
||||
@detectDelim
|
||||
32
node_modules/@lezer/javascript/src/parser.js
generated
vendored
Normal file
32
node_modules/@lezer/javascript/src/parser.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
106
node_modules/@lezer/javascript/src/parser.terms.js
generated
vendored
Normal file
106
node_modules/@lezer/javascript/src/parser.terms.js
generated
vendored
Normal file
@ -0,0 +1,106 @@
|
||||
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
||||
export const
|
||||
noSemi = 303,
|
||||
incdec = 1,
|
||||
incdecPrefix = 2,
|
||||
insertSemi = 304,
|
||||
spaces = 306,
|
||||
newline = 307,
|
||||
LineComment = 3,
|
||||
BlockComment = 4,
|
||||
Script = 5,
|
||||
ExportDeclaration = 6,
|
||||
Star = 8,
|
||||
VariableName = 10,
|
||||
String = 11,
|
||||
Escape = 12,
|
||||
FunctionDeclaration = 16,
|
||||
VariableDefinition = 19,
|
||||
TypeParamList = 21,
|
||||
TypeDefinition = 22,
|
||||
Number = 28,
|
||||
TemplateType = 30,
|
||||
InterpolationEnd = 31,
|
||||
templateType = 32,
|
||||
InterpolationStart = 33,
|
||||
typeofMemberExpression = 40,
|
||||
PropertyName = 43,
|
||||
TemplateString = 45,
|
||||
templateEscape = 46,
|
||||
templateExpr = 47,
|
||||
RegExp = 49,
|
||||
ArrayExpression = 51,
|
||||
Property = 57,
|
||||
PropertyDefinition = 61,
|
||||
Block = 62,
|
||||
TypeArgList = 66,
|
||||
LessThan = 67,
|
||||
ArgList = 71,
|
||||
UnaryExpression = 72,
|
||||
YieldExpression = 76,
|
||||
AwaitExpression = 78,
|
||||
ParenthesizedExpression = 80,
|
||||
ClassExpression = 81,
|
||||
ClassBody = 83,
|
||||
MethodDeclaration = 84,
|
||||
Decorator = 85,
|
||||
PrivatePropertyName = 88,
|
||||
PrivatePropertyDefinition = 95,
|
||||
PropertyDeclaration = 96,
|
||||
Optional = 99,
|
||||
TypeAnnotation = 100,
|
||||
StaticBlock = 102,
|
||||
FunctionExpression = 103,
|
||||
ArrowFunction = 104,
|
||||
ParamList = 106,
|
||||
ArrayPattern = 107,
|
||||
ObjectPattern = 108,
|
||||
PatternProperty = 109,
|
||||
MemberExpression = 113,
|
||||
BinaryExpression = 114,
|
||||
divide = 116,
|
||||
questionOp = 132,
|
||||
AssignmentExpression = 134,
|
||||
JSXElement = 142,
|
||||
JSXSelfCloseEndTag = 143,
|
||||
JSXStartTag = 144,
|
||||
JSXSelfClosingTag = 145,
|
||||
JSXIdentifier = 146,
|
||||
JSXLowerIdentifier = 148,
|
||||
JSXNamespacedName = 149,
|
||||
JSXMemberExpression = 150,
|
||||
JSXAttributeValue = 153,
|
||||
JSXEndTag = 155,
|
||||
JSXOpenTag = 156,
|
||||
JSXFragmentTag = 157,
|
||||
JSXText = 158,
|
||||
JSXEscape = 159,
|
||||
JSXStartCloseTag = 160,
|
||||
JSXCloseTag = 161,
|
||||
SequenceExpression = 165,
|
||||
TypeName = 173,
|
||||
ParamTypeList = 176,
|
||||
IndexedType = 178,
|
||||
Label = 180,
|
||||
ObjectType = 183,
|
||||
MethodType = 184,
|
||||
PropertyType = 185,
|
||||
IndexSignature = 186,
|
||||
TypePredicate = 189,
|
||||
ClassDeclaration = 199,
|
||||
VariableDeclaration = 203,
|
||||
TypeAliasDeclaration = 207,
|
||||
InterfaceDeclaration = 208,
|
||||
EnumDeclaration = 210,
|
||||
NamespaceDeclaration = 213,
|
||||
AmbientDeclaration = 216,
|
||||
ExportGroup = 223,
|
||||
ImportDeclaration = 226,
|
||||
ImportGroup = 227,
|
||||
ForSpec = 230,
|
||||
ForInSpec = 231,
|
||||
ForOfSpec = 232,
|
||||
SingleExpression = 267,
|
||||
SingleClassItem = 268,
|
||||
Dialect_jsx = 0,
|
||||
Dialect_ts = 1
|
||||
45
node_modules/@lezer/javascript/src/tokens.js
generated
vendored
Normal file
45
node_modules/@lezer/javascript/src/tokens.js
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
/* Hand-written tokenizers for JavaScript tokens that can't be
|
||||
expressed by lezer's built-in tokenizer. */
|
||||
|
||||
import {ExternalTokenizer, ContextTracker} from "@lezer/lr"
|
||||
import {insertSemi, noSemi, incdec, incdecPrefix,
|
||||
spaces, newline, BlockComment, LineComment} from "./parser.terms.js"
|
||||
|
||||
const space = [9, 10, 11, 12, 13, 32, 133, 160, 5760, 8192, 8193, 8194, 8195, 8196, 8197, 8198, 8199, 8200,
|
||||
8201, 8202, 8232, 8233, 8239, 8287, 12288]
|
||||
|
||||
const braceR = 125, semicolon = 59, slash = 47, star = 42, plus = 43, minus = 45
|
||||
|
||||
export const trackNewline = new ContextTracker({
|
||||
start: false,
|
||||
shift(context, term) {
|
||||
return term == LineComment || term == BlockComment || term == spaces ? context : term == newline
|
||||
},
|
||||
strict: false
|
||||
})
|
||||
|
||||
export const insertSemicolon = new ExternalTokenizer((input, stack) => {
|
||||
let {next} = input
|
||||
if (next == braceR || next == -1 || stack.context)
|
||||
input.acceptToken(insertSemi)
|
||||
}, {contextual: true, fallback: true})
|
||||
|
||||
export const noSemicolon = new ExternalTokenizer((input, stack) => {
|
||||
let {next} = input, after
|
||||
if (space.indexOf(next) > -1) return
|
||||
if (next == slash && ((after = input.peek(1)) == slash || after == star)) return
|
||||
if (next != braceR && next != semicolon && next != -1 && !stack.context)
|
||||
input.acceptToken(noSemi)
|
||||
}, {contextual: true})
|
||||
|
||||
export const incdecToken = new ExternalTokenizer((input, stack) => {
|
||||
let {next} = input
|
||||
if (next == plus || next == minus) {
|
||||
input.advance()
|
||||
if (next == input.next) {
|
||||
input.advance()
|
||||
let mayPostfix = !stack.context && stack.canShift(incdec)
|
||||
input.acceptToken(mayPostfix ? incdec : incdecPrefix)
|
||||
}
|
||||
}
|
||||
}, {contextual: true})
|
||||
1
node_modules/@lezer/javascript/test/.tern-port
generated
vendored
Normal file
1
node_modules/@lezer/javascript/test/.tern-port
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
46625
|
||||
64
node_modules/@lezer/javascript/test/decorator.txt
generated
vendored
Normal file
64
node_modules/@lezer/javascript/test/decorator.txt
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
# Decorators on classes and class fields
|
||||
|
||||
@d1 class Foo {
|
||||
@d2 bar() {}
|
||||
@d3 get baz() { return 1 }
|
||||
@d4 quux = 1
|
||||
}
|
||||
|
||||
==>
|
||||
|
||||
Script(ClassDeclaration(
|
||||
Decorator(VariableName),
|
||||
class,VariableDefinition,ClassBody(
|
||||
MethodDeclaration(Decorator(VariableName),PropertyDefinition,ParamList,Block),
|
||||
MethodDeclaration(Decorator(VariableName),get,PropertyDefinition,ParamList,Block(
|
||||
ReturnStatement(return,Number))),
|
||||
PropertyDeclaration(Decorator(VariableName),PropertyDefinition,Equals,Number))))
|
||||
|
||||
# Multiple decorators
|
||||
|
||||
@d1 @d2 class Y {}
|
||||
|
||||
==>
|
||||
|
||||
Script(ClassDeclaration(Decorator(VariableName),Decorator(VariableName),class,VariableDefinition,ClassBody))
|
||||
|
||||
# Member decorators
|
||||
|
||||
@one.two class X {}
|
||||
|
||||
==>
|
||||
|
||||
Script(ClassDeclaration(Decorator(MemberExpression(VariableName,PropertyName)),class,VariableDefinition,ClassBody))
|
||||
|
||||
# Call decorators
|
||||
|
||||
@d(2) @a.b() class Z {}
|
||||
|
||||
==>
|
||||
|
||||
Script(ClassDeclaration(
|
||||
Decorator(CallExpression(VariableName,ArgList(Number))),
|
||||
Decorator(CallExpression(MemberExpression(VariableName,PropertyName),ArgList)),
|
||||
class,VariableDefinition,ClassBody))
|
||||
|
||||
# Parenthesized decorators
|
||||
|
||||
@(a instanceof Array ? x : y)(2) class P {}
|
||||
|
||||
==>
|
||||
|
||||
Script(ClassDeclaration(
|
||||
Decorator(CallExpression(ParenthesizedExpression(
|
||||
ConditionalExpression(BinaryExpression(VariableName,instanceof,VariableName),LogicOp,VariableName,LogicOp,VariableName)),
|
||||
ArgList(Number))),
|
||||
class,VariableDefinition,ClassBody))
|
||||
|
||||
# Parameter decorators
|
||||
|
||||
function foo(@d bar) {}
|
||||
|
||||
==>
|
||||
|
||||
Script(FunctionDeclaration(function,VariableDefinition,ParamList(Decorator(VariableName),VariableDefinition),Block))
|
||||
678
node_modules/@lezer/javascript/test/expression.txt
generated
vendored
Normal file
678
node_modules/@lezer/javascript/test/expression.txt
generated
vendored
Normal file
@ -0,0 +1,678 @@
|
||||
# Minimal
|
||||
|
||||
0
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(Number))
|
||||
|
||||
# Strings
|
||||
|
||||
"A string with \"double\" and 'single' quotes";
|
||||
'A string with "double" and \'single\' quotes';
|
||||
'\\';
|
||||
"\\";
|
||||
|
||||
'A string with new \
|
||||
line';
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(String(Escape,Escape)),
|
||||
ExpressionStatement(String(Escape,Escape)),
|
||||
ExpressionStatement(String(Escape)),
|
||||
ExpressionStatement(String(Escape)),
|
||||
ExpressionStatement(String(Escape)))
|
||||
|
||||
# Numbers
|
||||
|
||||
101;
|
||||
3.14;
|
||||
3.14e+1;
|
||||
0x1ABCDEFabcdef;
|
||||
0o7632157312;
|
||||
0b1010101001;
|
||||
1e+3;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(Number),
|
||||
ExpressionStatement(Number),
|
||||
ExpressionStatement(Number),
|
||||
ExpressionStatement(Number),
|
||||
ExpressionStatement(Number),
|
||||
ExpressionStatement(Number),
|
||||
ExpressionStatement(Number))
|
||||
|
||||
# Identifiers
|
||||
|
||||
theVar;
|
||||
theVar2;
|
||||
$_;
|
||||
é象𫝄;
|
||||
últimaVez;
|
||||
県;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(VariableName),
|
||||
ExpressionStatement(VariableName),
|
||||
ExpressionStatement(VariableName),
|
||||
ExpressionStatement(VariableName),
|
||||
ExpressionStatement(VariableName),
|
||||
ExpressionStatement(VariableName))
|
||||
|
||||
# RegExps
|
||||
|
||||
/one\\/;
|
||||
/one/g;
|
||||
/one/i;
|
||||
/one/gim;
|
||||
/on\/e/gim;
|
||||
/on[^/]afe/gim;
|
||||
/[\]/]/;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(RegExp),
|
||||
ExpressionStatement(RegExp),
|
||||
ExpressionStatement(RegExp),
|
||||
ExpressionStatement(RegExp),
|
||||
ExpressionStatement(RegExp),
|
||||
ExpressionStatement(RegExp),
|
||||
ExpressionStatement(RegExp))
|
||||
|
||||
# Arrays
|
||||
|
||||
[];
|
||||
[ "item1" ];
|
||||
[ "item1", ];
|
||||
[ "item1", item2 ];
|
||||
[ , item2 ];
|
||||
[ item2 = 5 ];
|
||||
[ a, ...b, c ];
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(ArrayExpression),
|
||||
ExpressionStatement(ArrayExpression(String)),
|
||||
ExpressionStatement(ArrayExpression(String)),
|
||||
ExpressionStatement(ArrayExpression(String,VariableName)),
|
||||
ExpressionStatement(ArrayExpression(VariableName)),
|
||||
ExpressionStatement(ArrayExpression(AssignmentExpression(VariableName,Equals,Number))),
|
||||
ExpressionStatement(ArrayExpression(VariableName, Spread, VariableName, VariableName)))
|
||||
|
||||
# Functions
|
||||
|
||||
[
|
||||
function() {},
|
||||
function(arg1, ...arg2) {
|
||||
arg2;
|
||||
},
|
||||
function stuff() {},
|
||||
function trailing(a,) {},
|
||||
function trailing(a,b,) {}
|
||||
]
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(ArrayExpression(
|
||||
FunctionExpression(function,ParamList,Block),
|
||||
FunctionExpression(function,ParamList(VariableDefinition,Spread,VariableDefinition), Block(ExpressionStatement(VariableName))),
|
||||
FunctionExpression(function,VariableDefinition,ParamList,Block),
|
||||
FunctionExpression(function,VariableDefinition,ParamList(VariableDefinition), Block),
|
||||
FunctionExpression(function,VariableDefinition,ParamList(VariableDefinition,VariableDefinition),Block))))
|
||||
|
||||
# Arrow functions
|
||||
|
||||
a => 1;
|
||||
() => 2;
|
||||
(d, e) => 3;
|
||||
(f, g,) => {
|
||||
return h;
|
||||
};
|
||||
async () => 4;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(ArrowFunction(ParamList(VariableDefinition),Arrow,Number)),
|
||||
ExpressionStatement(ArrowFunction(ParamList,Arrow,Number)),
|
||||
ExpressionStatement(ArrowFunction(ParamList(VariableDefinition,VariableDefinition),Arrow,Number)),
|
||||
ExpressionStatement(ArrowFunction(ParamList(VariableDefinition,VariableDefinition),Arrow,Block(ReturnStatement(return,VariableName)))),
|
||||
ExpressionStatement(ArrowFunction(async,ParamList,Arrow,Number)))
|
||||
|
||||
# Arrow function followed by comma
|
||||
|
||||
({
|
||||
a: () => 1,
|
||||
b: "x"
|
||||
})
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(ParenthesizedExpression(ObjectExpression(
|
||||
Property(PropertyDefinition,ArrowFunction(ParamList,Arrow,Number)),
|
||||
Property(PropertyDefinition,String)))))
|
||||
|
||||
# Long potential arrow function
|
||||
|
||||
(assign = [to, from], from = assign[0], to = assign[1]);
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(ParenthesizedExpression(SequenceExpression(
|
||||
AssignmentExpression(VariableName,Equals,ArrayExpression(VariableName,VariableName)),
|
||||
AssignmentExpression(VariableName,Equals,MemberExpression(VariableName,Number)),
|
||||
AssignmentExpression(VariableName,Equals,MemberExpression(VariableName,Number))))))
|
||||
|
||||
# Ternary operator
|
||||
|
||||
condition ? case1 : case2;
|
||||
|
||||
x.y = some.condition ? 2**x : 1 - 2;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(ConditionalExpression(VariableName,LogicOp,VariableName,LogicOp,VariableName)),
|
||||
ExpressionStatement(AssignmentExpression(
|
||||
MemberExpression(VariableName,PropertyName),Equals,
|
||||
ConditionalExpression(
|
||||
MemberExpression(VariableName,PropertyName),LogicOp,
|
||||
BinaryExpression(Number,ArithOp,VariableName),LogicOp,
|
||||
BinaryExpression(Number,ArithOp,Number)))))
|
||||
|
||||
# Type operators
|
||||
|
||||
typeof x;
|
||||
x instanceof String;
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(UnaryExpression(typeof,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,instanceof,VariableName)))
|
||||
|
||||
# Delete
|
||||
|
||||
delete thing['prop'];
|
||||
true ? delete thing.prop : null;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(UnaryExpression(delete,MemberExpression(VariableName,String))),
|
||||
ExpressionStatement(ConditionalExpression(BooleanLiteral,LogicOp,
|
||||
UnaryExpression(delete,MemberExpression(VariableName,PropertyName)),LogicOp,null)))
|
||||
|
||||
# Void
|
||||
|
||||
a = void b();
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(AssignmentExpression(VariableName,Equals,UnaryExpression(void,CallExpression(VariableName,ArgList)))))
|
||||
|
||||
# Augmented assignment
|
||||
|
||||
s |= 1;
|
||||
t %= 2;
|
||||
w ^= 3;
|
||||
x += 4;
|
||||
y.z *= 5;
|
||||
z += 1;
|
||||
a >>= 1;
|
||||
b >>>= 1;
|
||||
c <<= 1;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
||||
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
||||
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
||||
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
||||
ExpressionStatement(AssignmentExpression(MemberExpression(VariableName,PropertyName),UpdateOp,Number)),
|
||||
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
||||
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
||||
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)),
|
||||
ExpressionStatement(AssignmentExpression(VariableName,UpdateOp,Number)))
|
||||
|
||||
# Operator precedence
|
||||
|
||||
a <= b && c >= d;
|
||||
a.b = c ? d : e;
|
||||
a && b(c) && d;
|
||||
a && new b(c) && d;
|
||||
typeof a == b && c instanceof d;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName,CompareOp,VariableName),LogicOp,
|
||||
BinaryExpression(VariableName,CompareOp,VariableName))),
|
||||
ExpressionStatement(AssignmentExpression(MemberExpression(VariableName,PropertyName),Equals,
|
||||
ConditionalExpression(VariableName,LogicOp,VariableName,LogicOp,VariableName))),
|
||||
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName,LogicOp,CallExpression(VariableName,ArgList(VariableName))),LogicOp,
|
||||
VariableName)),
|
||||
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName,LogicOp,NewExpression(new,VariableName,ArgList(VariableName))),LogicOp,
|
||||
VariableName)),
|
||||
ExpressionStatement(BinaryExpression(BinaryExpression(UnaryExpression(typeof,VariableName),CompareOp,VariableName),LogicOp,
|
||||
BinaryExpression(VariableName,instanceof,VariableName))))
|
||||
|
||||
# Rest args
|
||||
|
||||
foo(...rest);
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(CallExpression(VariableName,ArgList(Spread,VariableName))))
|
||||
|
||||
# Forward slashes after parenthesized expressions
|
||||
|
||||
(foo - bar) / baz;
|
||||
if (foo - bar) /baz/;
|
||||
(this.a() / this.b() - 1) / 2;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(BinaryExpression(ParenthesizedExpression(BinaryExpression(VariableName,ArithOp,VariableName)),ArithOp,VariableName)),
|
||||
IfStatement(if,ParenthesizedExpression(BinaryExpression(VariableName,ArithOp,VariableName)),
|
||||
ExpressionStatement(RegExp)),
|
||||
ExpressionStatement(BinaryExpression(ParenthesizedExpression(
|
||||
BinaryExpression(
|
||||
BinaryExpression(
|
||||
CallExpression(MemberExpression(this,PropertyName),ArgList),ArithOp,
|
||||
CallExpression(MemberExpression(this,PropertyName),ArgList)),ArithOp,Number)),ArithOp,Number)))
|
||||
|
||||
# Yield expressions
|
||||
|
||||
yield db.users.where('[endpoint+email]');
|
||||
yield* a;
|
||||
yield [22];
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(YieldExpression(yield,
|
||||
CallExpression(MemberExpression(MemberExpression(VariableName,PropertyName),PropertyName),ArgList(String)))),
|
||||
ExpressionStatement(YieldExpression(yield,Star,VariableName)),
|
||||
ExpressionStatement(YieldExpression(yield,ArrayExpression(Number))))
|
||||
|
||||
# Template strings
|
||||
|
||||
`one line`;
|
||||
`multi
|
||||
line`;
|
||||
|
||||
`multi
|
||||
${2 + 2}
|
||||
hello
|
||||
${1, 2}
|
||||
line`;
|
||||
|
||||
`$$$$`;
|
||||
`$`;
|
||||
`$$$$${ async }`;
|
||||
|
||||
`\\\``;
|
||||
|
||||
`one${`two${`three`}`}`;
|
||||
|
||||
f`hi${there}`;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(TemplateString),
|
||||
ExpressionStatement(TemplateString),
|
||||
ExpressionStatement(TemplateString(
|
||||
Interpolation(InterpolationStart,BinaryExpression(Number,ArithOp,Number),InterpolationEnd),
|
||||
Interpolation(InterpolationStart,SequenceExpression(Number,Number),InterpolationEnd))),
|
||||
ExpressionStatement(TemplateString),
|
||||
ExpressionStatement(TemplateString),
|
||||
ExpressionStatement(TemplateString(Interpolation(InterpolationStart,VariableName,InterpolationEnd))),
|
||||
ExpressionStatement(TemplateString(Escape,Escape)),
|
||||
ExpressionStatement(TemplateString(Interpolation(InterpolationStart,TemplateString(
|
||||
Interpolation(InterpolationStart,TemplateString,InterpolationEnd)),InterpolationEnd))),
|
||||
ExpressionStatement(TaggedTemplateExpression(VariableName,TemplateString(
|
||||
Interpolation(InterpolationStart,VariableName,InterpolationEnd)))))
|
||||
|
||||
# Atoms
|
||||
|
||||
this;
|
||||
null;
|
||||
undefined;
|
||||
true;
|
||||
false;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(this),
|
||||
ExpressionStatement(null),
|
||||
ExpressionStatement(VariableName),
|
||||
ExpressionStatement(BooleanLiteral),
|
||||
ExpressionStatement(BooleanLiteral))
|
||||
|
||||
# Objects
|
||||
|
||||
foo({},
|
||||
{ a: "b" },
|
||||
{ c: "d", "e": f, 1: 2 },
|
||||
{
|
||||
g,
|
||||
[methodName]() {}
|
||||
},
|
||||
{b, get},
|
||||
{a,});
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(CallExpression(VariableName,ArgList(
|
||||
ObjectExpression,
|
||||
ObjectExpression(Property(PropertyDefinition,String)),
|
||||
ObjectExpression(Property(PropertyDefinition,String),Property(String,VariableName),Property(Number,Number)),
|
||||
ObjectExpression(Property(PropertyDefinition),Property(VariableName,ParamList,Block)),
|
||||
ObjectExpression(Property(PropertyDefinition),Property(PropertyDefinition)),
|
||||
ObjectExpression(Property(PropertyDefinition))))))
|
||||
|
||||
# Method definitions
|
||||
|
||||
({
|
||||
foo: true,
|
||||
|
||||
add(a, b) {
|
||||
return a + b;
|
||||
},
|
||||
|
||||
get bar() { return c; },
|
||||
|
||||
set bar(a) { c = a; },
|
||||
|
||||
*barGenerator() { yield c; },
|
||||
|
||||
get() { return 1; }
|
||||
});
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(ParenthesizedExpression(ObjectExpression(
|
||||
Property(PropertyDefinition,BooleanLiteral),
|
||||
Property(PropertyDefinition,ParamList(VariableDefinition,VariableDefinition),
|
||||
Block(ReturnStatement(return,BinaryExpression(VariableName,ArithOp,VariableName)))),
|
||||
Property(get,PropertyDefinition,ParamList,Block(ReturnStatement(return,VariableName))),
|
||||
Property(set,PropertyDefinition,ParamList(VariableDefinition),
|
||||
Block(ExpressionStatement(AssignmentExpression(VariableName,Equals,VariableName)))),
|
||||
Property(Star,PropertyDefinition,ParamList,Block(ExpressionStatement(YieldExpression(yield,VariableName)))),
|
||||
Property(PropertyDefinition,ParamList,Block(ReturnStatement(return,Number)))))))
|
||||
|
||||
# Keyword property names
|
||||
|
||||
({
|
||||
finally() {},
|
||||
catch() {},
|
||||
get: function () {},
|
||||
set() {},
|
||||
static: true,
|
||||
async: true,
|
||||
});
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(ParenthesizedExpression(ObjectExpression(
|
||||
Property(PropertyDefinition,ParamList,Block),
|
||||
Property(PropertyDefinition,ParamList,Block),
|
||||
Property(PropertyDefinition,FunctionExpression(function,ParamList,Block)),
|
||||
Property(PropertyDefinition,ParamList,Block),
|
||||
Property(PropertyDefinition,BooleanLiteral),
|
||||
Property(PropertyDefinition,BooleanLiteral)))))
|
||||
|
||||
# Generator functions
|
||||
|
||||
[
|
||||
function *() {},
|
||||
function *generateStuff(arg1, arg2) {
|
||||
yield;
|
||||
yield arg2;
|
||||
}
|
||||
];
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(ArrayExpression(
|
||||
FunctionExpression(function,Star,ParamList,Block),
|
||||
FunctionExpression(function,Star,VariableDefinition,ParamList(VariableDefinition,VariableDefinition),Block(
|
||||
ExpressionStatement(VariableName),
|
||||
ExpressionStatement(YieldExpression(yield,VariableName)))))))
|
||||
|
||||
# Member expressions
|
||||
|
||||
x.someProperty;
|
||||
x?.other;
|
||||
x[someVariable];
|
||||
f()["some-string"];
|
||||
return returned.promise().done(a).fail(b);
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(MemberExpression(VariableName,PropertyName)),
|
||||
ExpressionStatement(MemberExpression(VariableName,PropertyName)),
|
||||
ExpressionStatement(MemberExpression(VariableName,VariableName)),
|
||||
ExpressionStatement(MemberExpression(CallExpression(VariableName,ArgList),String)),
|
||||
ReturnStatement(return,CallExpression(MemberExpression(CallExpression(MemberExpression(CallExpression(
|
||||
MemberExpression(VariableName,PropertyName),ArgList),PropertyName),ArgList(VariableName)),PropertyName),ArgList(VariableName))))
|
||||
|
||||
# Callback chain
|
||||
|
||||
return this.map(function (a) {
|
||||
return a.b;
|
||||
})
|
||||
|
||||
// a comment
|
||||
|
||||
.filter(function (c) {
|
||||
return 2;
|
||||
});
|
||||
|
||||
==>
|
||||
|
||||
Script(ReturnStatement(return,CallExpression(MemberExpression(CallExpression(MemberExpression(this,PropertyName),
|
||||
ArgList(FunctionExpression(function,ParamList(VariableDefinition),Block(ReturnStatement(return,MemberExpression(VariableName,PropertyName)))))),
|
||||
LineComment,PropertyName),ArgList(FunctionExpression(function,ParamList(VariableDefinition),Block(ReturnStatement(return,Number)))))))
|
||||
|
||||
# Function calls
|
||||
|
||||
x.someMethod(arg1, "arg2");
|
||||
(function(x, y) {
|
||||
|
||||
}(a, b));
|
||||
f(new foo.bar(1), 2);
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(CallExpression(MemberExpression(VariableName,PropertyName),ArgList(VariableName,String))),
|
||||
ExpressionStatement(ParenthesizedExpression(CallExpression(FunctionExpression(function,ParamList(VariableDefinition,VariableDefinition),Block),
|
||||
ArgList(VariableName,VariableName)))),
|
||||
ExpressionStatement(CallExpression(VariableName,ArgList(NewExpression(new,MemberExpression(VariableName,PropertyName),ArgList(Number)),Number))))
|
||||
|
||||
# Constructor calls
|
||||
|
||||
new foo(1);
|
||||
new module.Klass(1, "two");
|
||||
new Thing;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(NewExpression(new,VariableName,ArgList(Number))),
|
||||
ExpressionStatement(NewExpression(new,MemberExpression(VariableName,PropertyName),ArgList(Number,String))),
|
||||
ExpressionStatement(NewExpression(new,VariableName)))
|
||||
|
||||
# Await Expressions
|
||||
|
||||
await asyncFunction();
|
||||
await asyncPromise;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(AwaitExpression(await,CallExpression(VariableName,ArgList))),
|
||||
ExpressionStatement(AwaitExpression(await,VariableName)))
|
||||
|
||||
# Numeric operators
|
||||
|
||||
i++;
|
||||
i--;
|
||||
i + j * 3 - j % 5;
|
||||
2 ** i * 3;
|
||||
2 * i ** 3;
|
||||
+x;
|
||||
-x;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(PostfixExpression(VariableName,ArithOp)),
|
||||
ExpressionStatement(PostfixExpression(VariableName,ArithOp)),
|
||||
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName,ArithOp,BinaryExpression(VariableName,ArithOp,Number)),ArithOp,BinaryExpression(VariableName,ArithOp,Number))),
|
||||
ExpressionStatement(BinaryExpression(BinaryExpression(Number,ArithOp,VariableName),ArithOp,Number)),
|
||||
ExpressionStatement(BinaryExpression(Number,ArithOp,BinaryExpression(VariableName,ArithOp,Number))),
|
||||
ExpressionStatement(UnaryExpression(ArithOp,VariableName)),
|
||||
ExpressionStatement(UnaryExpression(ArithOp,VariableName)))
|
||||
|
||||
# Boolean operators
|
||||
|
||||
i || j;
|
||||
i && j;
|
||||
i ?? j;
|
||||
!a && !b || !c && !d;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(BinaryExpression(VariableName,LogicOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,LogicOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,LogicOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(BinaryExpression(UnaryExpression(LogicOp,VariableName),LogicOp,
|
||||
UnaryExpression(LogicOp,VariableName)),LogicOp,BinaryExpression(UnaryExpression(LogicOp,VariableName),LogicOp,
|
||||
UnaryExpression(LogicOp,VariableName)))))
|
||||
|
||||
# Bitwise operators
|
||||
|
||||
i >> j;
|
||||
i >>> j;
|
||||
i << j;
|
||||
i & j;
|
||||
i | j;
|
||||
~i ^ ~j;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,BitOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(UnaryExpression(BitOp,VariableName),BitOp,UnaryExpression(BitOp,VariableName))))
|
||||
|
||||
# Relational operators
|
||||
|
||||
x < y;
|
||||
x <= y;
|
||||
x == y;
|
||||
x === y;
|
||||
x != y;
|
||||
x !== y;
|
||||
x > y;
|
||||
x >= y;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,CompareOp,VariableName)))
|
||||
|
||||
# Word operators
|
||||
|
||||
x in y;
|
||||
x instanceof y;
|
||||
!x instanceof y;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(BinaryExpression(VariableName,in,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(VariableName,instanceof,VariableName)),
|
||||
ExpressionStatement(BinaryExpression(UnaryExpression(LogicOp,VariableName),instanceof,VariableName)))
|
||||
|
||||
# Assignments
|
||||
|
||||
x = 0;
|
||||
x.y = 0;
|
||||
x["y"] = 0;
|
||||
async = 0;
|
||||
[a, b = 2] = foo;
|
||||
({a, b, ...d} = c);
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(AssignmentExpression(VariableName,Equals,Number)),
|
||||
ExpressionStatement(AssignmentExpression(MemberExpression(VariableName,PropertyName),Equals,Number)),
|
||||
ExpressionStatement(AssignmentExpression(MemberExpression(VariableName,String),Equals,Number)),
|
||||
ExpressionStatement(AssignmentExpression(VariableName,Equals,Number)),
|
||||
ExpressionStatement(AssignmentExpression(ArrayPattern(VariableDefinition,VariableDefinition,Equals,Number),Equals,VariableName)),
|
||||
ExpressionStatement(ParenthesizedExpression(AssignmentExpression(ObjectPattern(
|
||||
PatternProperty(PropertyName),PatternProperty(PropertyName),PatternProperty(Spread,VariableDefinition)),Equals,VariableName))))
|
||||
|
||||
# Comma operator
|
||||
|
||||
a = 1, b = 2;
|
||||
c = {d: (3, 4 + 5)};
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(SequenceExpression(AssignmentExpression(VariableName,Equals,Number),AssignmentExpression(VariableName,Equals,Number))),
|
||||
ExpressionStatement(AssignmentExpression(VariableName,Equals,ObjectExpression(
|
||||
Property(PropertyDefinition,ParenthesizedExpression(SequenceExpression(Number,BinaryExpression(Number,ArithOp,Number))))))))
|
||||
|
||||
# Punctuation
|
||||
|
||||
(foo(1, 2), bar);
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(ParenthesizedExpression(
|
||||
"(",SequenceExpression(CallExpression(VariableName,ArgList("(",Number,Number,")")),",",VariableName),")")))
|
||||
|
||||
# Doesn't choke on unfinished ternary operator
|
||||
|
||||
1?1
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(ConditionalExpression(Number,LogicOp,Number,⚠)))
|
||||
|
||||
# Can handle unterminated template literals
|
||||
|
||||
`f
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(TemplateString(⚠)))
|
||||
79
node_modules/@lezer/javascript/test/jsx.txt
generated
vendored
Normal file
79
node_modules/@lezer/javascript/test/jsx.txt
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
# Self-closing element {"dialect": "jsx"}
|
||||
|
||||
<img/>
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(JSXElement(JSXSelfClosingTag(JSXStartTag,JSXBuiltin(JSXIdentifier),JSXSelfCloseEndTag))))
|
||||
|
||||
# Regular element {"dialect": "jsx"}
|
||||
|
||||
<Foo>bar</Foo>
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(JSXElement(
|
||||
JSXOpenTag(JSXStartTag, JSXIdentifier, JSXEndTag),
|
||||
JSXText,
|
||||
JSXCloseTag(JSXStartCloseTag, JSXIdentifier, JSXEndTag))))
|
||||
|
||||
# Fragment {"dialect": "jsx"}
|
||||
|
||||
<>bar</>
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(JSXElement(
|
||||
JSXFragmentTag(JSXStartTag, JSXEndTag),
|
||||
JSXText,
|
||||
JSXCloseTag(JSXStartCloseTag, JSXEndTag))))
|
||||
|
||||
# Namespaced name {"dialect": "jsx"}
|
||||
|
||||
<blah-namespace:img/>
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(JSXElement(
|
||||
JSXSelfClosingTag(JSXStartTag,JSXNamespacedName(JSXIdentifier, JSXIdentifier),JSXSelfCloseEndTag))))
|
||||
|
||||
# Member name {"dialect": "jsx"}
|
||||
|
||||
<pkg.Component/>
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(JSXElement(
|
||||
JSXSelfClosingTag(JSXStartTag,JSXMemberExpression(JSXIdentifier, JSXIdentifier),JSXSelfCloseEndTag))))
|
||||
|
||||
# Nested tags {"dialect": "jsx"}
|
||||
|
||||
<a><b.C>text</b.C>{x} {...y}</a>
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(JSXElement(
|
||||
JSXOpenTag(JSXStartTag, JSXBuiltin(JSXIdentifier), JSXEndTag),
|
||||
JSXElement(
|
||||
JSXOpenTag(JSXStartTag, JSXMemberExpression(JSXIdentifier, JSXIdentifier), JSXEndTag),
|
||||
JSXText,
|
||||
JSXCloseTag(JSXStartCloseTag, JSXMemberExpression(JSXIdentifier, JSXIdentifier), JSXEndTag)),
|
||||
JSXEscape(VariableName),
|
||||
JSXText,
|
||||
JSXEscape(Spread, VariableName),
|
||||
JSXCloseTag(JSXStartCloseTag, JSXBuiltin(JSXIdentifier), JSXEndTag))))
|
||||
|
||||
# Attributes {"dialect": "jsx"}
|
||||
|
||||
<Foo a="1" b {...attrs} c={c}></Foo>
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(JSXElement(
|
||||
JSXOpenTag(JSXStartTag, JSXIdentifier,
|
||||
JSXAttribute(JSXIdentifier, Equals, JSXAttributeValue),
|
||||
JSXAttribute(JSXIdentifier),
|
||||
JSXSpreadAttribute(Spread, VariableName),
|
||||
JSXAttribute(JSXIdentifier, Equals, JSXEscape(VariableName)),
|
||||
JSXEndTag),
|
||||
JSXCloseTag(JSXStartCloseTag, JSXIdentifier, JSXEndTag))))
|
||||
77
node_modules/@lezer/javascript/test/semicolon.txt
generated
vendored
Normal file
77
node_modules/@lezer/javascript/test/semicolon.txt
generated
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
# No semicolons
|
||||
|
||||
x
|
||||
if (a) {
|
||||
var b = c
|
||||
d
|
||||
} else
|
||||
e
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(VariableName),
|
||||
IfStatement(if,ParenthesizedExpression(VariableName),Block(
|
||||
VariableDeclaration(var,VariableDefinition,Equals,VariableName),
|
||||
ExpressionStatement(VariableName)),
|
||||
else,ExpressionStatement(VariableName)))
|
||||
|
||||
# Continued expressions on new line
|
||||
|
||||
x
|
||||
+ 2
|
||||
foo
|
||||
(bar)
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(BinaryExpression(VariableName,ArithOp,Number)),
|
||||
ExpressionStatement(CallExpression(VariableName,ArgList(VariableName))))
|
||||
|
||||
# Doesn't parse postfix ops on a new line
|
||||
|
||||
x
|
||||
++y
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(VariableName),
|
||||
ExpressionStatement(UnaryExpression(ArithOp,VariableName)))
|
||||
|
||||
# Eagerly cut return/break/continue
|
||||
|
||||
return 2
|
||||
return
|
||||
2
|
||||
continue foo
|
||||
continue
|
||||
foo
|
||||
break bar
|
||||
break
|
||||
bar
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ReturnStatement(return,Number),
|
||||
ReturnStatement(return),
|
||||
ExpressionStatement(Number),
|
||||
ContinueStatement(continue,Label),
|
||||
ContinueStatement(continue),
|
||||
ExpressionStatement(VariableName),
|
||||
BreakStatement(break,Label),
|
||||
BreakStatement(break),
|
||||
ExpressionStatement(VariableName))
|
||||
|
||||
# Cut return regardless of whitespace
|
||||
|
||||
{ return }
|
||||
|
||||
return // foo
|
||||
;
|
||||
|
||||
==>
|
||||
|
||||
Script(Block(ReturnStatement(return)),ReturnStatement(return,LineComment))
|
||||
376
node_modules/@lezer/javascript/test/statement.txt
generated
vendored
Normal file
376
node_modules/@lezer/javascript/test/statement.txt
generated
vendored
Normal file
@ -0,0 +1,376 @@
|
||||
# Variable declaration
|
||||
|
||||
var a = b
|
||||
, c = d;
|
||||
const [x] = y = 3;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
VariableDeclaration(var,VariableDefinition,Equals,VariableName,VariableDefinition,Equals,VariableName),
|
||||
VariableDeclaration(const,ArrayPattern(VariableDefinition),Equals,AssignmentExpression(VariableName,Equals,Number)))
|
||||
|
||||
# Function declaration
|
||||
|
||||
function a(a, b) { return 3; }
|
||||
function b({b}, c = d, e = f) {}
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
FunctionDeclaration(function,VariableDefinition,ParamList(VariableDefinition,VariableDefinition),Block(ReturnStatement(return,Number))),
|
||||
FunctionDeclaration(function,VariableDefinition,ParamList(
|
||||
ObjectPattern(PatternProperty(PropertyName)),VariableDefinition,Equals,VariableName,VariableDefinition,Equals,VariableName),Block))
|
||||
|
||||
# Async functions
|
||||
|
||||
async function foo() {}
|
||||
|
||||
class Foo { async bar() {} }
|
||||
|
||||
async (a) => { return foo; };
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
FunctionDeclaration(async,function,VariableDefinition,ParamList,Block),
|
||||
ClassDeclaration(class,VariableDefinition,ClassBody(MethodDeclaration(async,PropertyDefinition,ParamList,Block))),
|
||||
ExpressionStatement(ArrowFunction(async,ParamList(VariableDefinition),Arrow,Block(ReturnStatement(return,VariableName)))))
|
||||
|
||||
# If statements
|
||||
|
||||
if (x) log(y);
|
||||
|
||||
if (a.b) {
|
||||
d;
|
||||
}
|
||||
|
||||
if (a) {
|
||||
c;
|
||||
d;
|
||||
} else {
|
||||
e;
|
||||
}
|
||||
|
||||
if (1) if (2) b; else c;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
IfStatement(if,ParenthesizedExpression(VariableName),ExpressionStatement(CallExpression(VariableName,ArgList(VariableName)))),
|
||||
IfStatement(if,ParenthesizedExpression(MemberExpression(VariableName,PropertyName)),Block(ExpressionStatement(VariableName))),
|
||||
IfStatement(if,ParenthesizedExpression(VariableName),Block(ExpressionStatement(VariableName),ExpressionStatement(VariableName)),
|
||||
else,Block(ExpressionStatement(VariableName))),
|
||||
IfStatement(if,ParenthesizedExpression(Number),IfStatement(if,ParenthesizedExpression(Number),ExpressionStatement(VariableName),
|
||||
else,ExpressionStatement(VariableName))))
|
||||
|
||||
# While loop
|
||||
|
||||
while (1) debugger;
|
||||
while (2) {
|
||||
a;
|
||||
b;
|
||||
}
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
WhileStatement(while,ParenthesizedExpression(Number),DebuggerStatement(debugger)),
|
||||
WhileStatement(while,ParenthesizedExpression(Number),Block(ExpressionStatement(VariableName),ExpressionStatement(VariableName))))
|
||||
|
||||
# Labels
|
||||
|
||||
foo: 1;
|
||||
foo: while(2) break foo;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
LabeledStatement(Label,ExpressionStatement(Number)),
|
||||
LabeledStatement(Label,WhileStatement(while,ParenthesizedExpression(Number),BreakStatement(break,Label))))
|
||||
|
||||
# Try
|
||||
|
||||
try { throw new Error; } catch {}
|
||||
try { 1; } catch (x) { 2; } finally { 3; }
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
TryStatement(try,Block(ThrowStatement(throw,NewExpression(new,VariableName))),CatchClause(catch,Block)),
|
||||
TryStatement(try,Block(ExpressionStatement(Number)),
|
||||
CatchClause(catch,VariableDefinition,Block(ExpressionStatement(Number))),
|
||||
FinallyClause(finally,Block(ExpressionStatement(Number)))))
|
||||
|
||||
# Switch
|
||||
|
||||
switch (x) {
|
||||
case 1:
|
||||
return true;
|
||||
case 2:
|
||||
case 50 * 3:
|
||||
console.log("ok");
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
==>
|
||||
|
||||
Script(SwitchStatement(switch,ParenthesizedExpression(VariableName),SwitchBody(
|
||||
CaseLabel(case,Number),
|
||||
ReturnStatement(return,BooleanLiteral),
|
||||
CaseLabel(case,Number),
|
||||
CaseLabel(case,BinaryExpression(Number,ArithOp,Number)),
|
||||
ExpressionStatement(CallExpression(MemberExpression(VariableName,PropertyName),ArgList(String))),
|
||||
DefaultLabel(default),
|
||||
ReturnStatement(return,BooleanLiteral))))
|
||||
|
||||
# For
|
||||
|
||||
for (let x = 1; x < 10; x++) {}
|
||||
for (const y of z) {}
|
||||
for (var m in n) {}
|
||||
for (q in r) {}
|
||||
for (var a, b; c; d) continue;
|
||||
for (i = 0, init(); i < 10; i++) {}
|
||||
for (;;) {}
|
||||
for (const {thing} in things) thing;
|
||||
for await (let x of stream) {}
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ForStatement(for,ForSpec(VariableDeclaration(let,VariableDefinition,Equals,Number),
|
||||
BinaryExpression(VariableName,CompareOp,Number),PostfixExpression(VariableName,ArithOp)),Block),
|
||||
ForStatement(for,ForOfSpec(const,VariableDefinition,of,VariableName),Block),
|
||||
ForStatement(for,ForInSpec(var,VariableDefinition,in,VariableName),Block),
|
||||
ForStatement(for,ForInSpec(VariableName,in,VariableName),Block),
|
||||
ForStatement(for,ForSpec(VariableDeclaration(var,VariableDefinition,VariableDefinition),VariableName,VariableName),ContinueStatement(continue)),
|
||||
ForStatement(for,ForSpec(SequenceExpression(AssignmentExpression(VariableName,Equals,Number),
|
||||
CallExpression(VariableName,ArgList)),BinaryExpression(VariableName,CompareOp,Number),PostfixExpression(VariableName,ArithOp)),Block),
|
||||
ForStatement(for,ForSpec,Block),
|
||||
ForStatement(for,ForInSpec(const,ObjectPattern(PatternProperty(PropertyName)),in,VariableName),ExpressionStatement(VariableName)),
|
||||
ForStatement(for,await,ForOfSpec(let,VariableDefinition,of,VariableName),Block))
|
||||
|
||||
# Labeled statements
|
||||
|
||||
theLoop: for (;;) {
|
||||
if (a) {
|
||||
break theLoop;
|
||||
}
|
||||
}
|
||||
|
||||
==>
|
||||
|
||||
Script(LabeledStatement(Label,ForStatement(for,ForSpec,Block(
|
||||
IfStatement(if,ParenthesizedExpression(VariableName),Block(BreakStatement(break,Label)))))))
|
||||
|
||||
# Classes
|
||||
|
||||
class Foo {
|
||||
static one(a) { return a; };
|
||||
two(b) { return b; }
|
||||
finally() {}
|
||||
}
|
||||
|
||||
class Foo extends require('another-class') {
|
||||
constructor() { super(); }
|
||||
bar() { super.a(); }
|
||||
prop;
|
||||
etc = 20;
|
||||
static { f() }
|
||||
}
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ClassDeclaration(class,VariableDefinition,ClassBody(
|
||||
MethodDeclaration(static,PropertyDefinition,ParamList(VariableDefinition),Block(ReturnStatement(return,VariableName))),
|
||||
MethodDeclaration(PropertyDefinition,ParamList(VariableDefinition),Block(ReturnStatement(return,VariableName))),
|
||||
MethodDeclaration(PropertyDefinition,ParamList,Block))),
|
||||
ClassDeclaration(class,VariableDefinition,extends,CallExpression(VariableName,ArgList(String)),ClassBody(
|
||||
MethodDeclaration(PropertyDefinition,ParamList,Block(ExpressionStatement(CallExpression(super,ArgList)))),
|
||||
MethodDeclaration(PropertyDefinition,ParamList,Block(ExpressionStatement(CallExpression(MemberExpression(super,PropertyName),ArgList)))),
|
||||
PropertyDeclaration(PropertyDefinition),
|
||||
PropertyDeclaration(PropertyDefinition,Equals,Number),
|
||||
StaticBlock(static, Block(ExpressionStatement(CallExpression(VariableName,ArgList)))))))
|
||||
|
||||
# Private properties
|
||||
|
||||
class Foo {
|
||||
#bar() { this.#a() + this?.#prop == #prop in this; }
|
||||
#prop;
|
||||
#etc = 20;
|
||||
}
|
||||
|
||||
==>
|
||||
|
||||
Script(ClassDeclaration(class,VariableDefinition,ClassBody(
|
||||
MethodDeclaration(PrivatePropertyDefinition,ParamList,Block(
|
||||
ExpressionStatement(BinaryExpression(
|
||||
BinaryExpression(
|
||||
CallExpression(MemberExpression(this,PrivatePropertyName),ArgList),
|
||||
ArithOp,
|
||||
MemberExpression(this,PrivatePropertyName)),
|
||||
CompareOp,
|
||||
BinaryExpression(PrivatePropertyName, in, this))))),
|
||||
PropertyDeclaration(PrivatePropertyDefinition),
|
||||
PropertyDeclaration(PrivatePropertyDefinition,Equals,Number))))
|
||||
|
||||
# Computed properties
|
||||
|
||||
class Foo {
|
||||
[x] = 44;
|
||||
[Symbol.iterator]() {}
|
||||
}
|
||||
|
||||
==>
|
||||
|
||||
Script(ClassDeclaration(class,VariableDefinition,ClassBody(
|
||||
PropertyDeclaration(VariableName,Equals,Number),
|
||||
MethodDeclaration(MemberExpression(VariableName,PropertyName),ParamList,Block))))
|
||||
|
||||
# Imports
|
||||
|
||||
import defaultMember from "module-name";
|
||||
import * as name from "module-name";
|
||||
import { member } from "module-name";
|
||||
import { member1, member2 as alias2 } from "module-name";
|
||||
import defaultMember, { member1, member2 as alias2, } from "module-name";
|
||||
import "module-name";
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ImportDeclaration(import,VariableDefinition,from,String),
|
||||
ImportDeclaration(import,Star,as,VariableDefinition,from,String),
|
||||
ImportDeclaration(import,ImportGroup(VariableDefinition),from,String),
|
||||
ImportDeclaration(import,ImportGroup(VariableDefinition,VariableName,as,VariableDefinition),from,String),
|
||||
ImportDeclaration(import,VariableDefinition,ImportGroup(VariableDefinition,VariableName,as,VariableDefinition),from,String),
|
||||
ImportDeclaration(import,String))
|
||||
|
||||
# Exports
|
||||
|
||||
export { name1, name2, name3 as x, nameN };
|
||||
export let a, b = 2;
|
||||
export default 2 + 2;
|
||||
export default function() { }
|
||||
export default async function name1() { }
|
||||
export { name1 as default, } from "foo";
|
||||
export * from 'foo';
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExportDeclaration(export,ExportGroup(VariableName,VariableName,VariableName,as,VariableName,VariableName)),
|
||||
ExportDeclaration(export,VariableDeclaration(let,VariableDefinition,VariableDefinition,Equals,Number)),
|
||||
ExportDeclaration(export,default,BinaryExpression(Number,ArithOp,Number)),
|
||||
ExportDeclaration(export,default,FunctionDeclaration(function,ParamList,Block)),
|
||||
ExportDeclaration(export,default,FunctionDeclaration(async,function,VariableDefinition,ParamList,Block)),
|
||||
ExportDeclaration(export,ExportGroup(VariableName,as,VariableName),from,String),
|
||||
ExportDeclaration(export,Star,from,String))
|
||||
|
||||
# Empty statements
|
||||
|
||||
if (true) { ; };;;
|
||||
|
||||
==>
|
||||
|
||||
Script(IfStatement(if,ParenthesizedExpression(BooleanLiteral),Block))
|
||||
|
||||
# Comments
|
||||
|
||||
/* a */
|
||||
one;
|
||||
|
||||
/* b **/
|
||||
two;
|
||||
|
||||
/* c ***/
|
||||
three;
|
||||
|
||||
/* d
|
||||
|
||||
***/
|
||||
four;
|
||||
|
||||
y // comment
|
||||
* z;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
BlockComment,
|
||||
ExpressionStatement(VariableName),
|
||||
BlockComment,
|
||||
ExpressionStatement(VariableName),
|
||||
BlockComment,
|
||||
ExpressionStatement(VariableName),
|
||||
BlockComment,
|
||||
ExpressionStatement(VariableName),
|
||||
ExpressionStatement(BinaryExpression(VariableName,LineComment,ArithOp,VariableName)))
|
||||
|
||||
# Recover from invalid char
|
||||
|
||||
const {foobar} = {};
|
||||
|
||||
==>
|
||||
|
||||
Script(VariableDeclaration(
|
||||
const,
|
||||
ObjectPattern("{",PatternProperty(PropertyName,⚠),"}"),
|
||||
Equals,
|
||||
ObjectExpression))
|
||||
|
||||
# Sync back to statement
|
||||
|
||||
function f() {
|
||||
log(a b --c)
|
||||
}
|
||||
function g() {}
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
FunctionDeclaration(function,VariableDefinition,ParamList,Block(ExpressionStatement(CallExpression(VariableName,ArgList(...))))),
|
||||
FunctionDeclaration(function,VariableDefinition,ParamList,Block))
|
||||
|
||||
# Destructuring
|
||||
|
||||
({x} = y);
|
||||
[u, v] = w;
|
||||
let [a,, b = 0] = c;
|
||||
let {x, y: z = 1} = d;
|
||||
let {[f]: m} = e;
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(ParenthesizedExpression(AssignmentExpression(
|
||||
ObjectPattern(PatternProperty(PropertyName)),Equals,VariableName))),
|
||||
ExpressionStatement(AssignmentExpression(ArrayPattern(VariableDefinition,VariableDefinition),Equals,VariableName)),
|
||||
VariableDeclaration(let,ArrayPattern(VariableDefinition,VariableDefinition,Equals,Number),Equals,VariableName),
|
||||
VariableDeclaration(let,ObjectPattern(
|
||||
PatternProperty(PropertyName),
|
||||
PatternProperty(PropertyName,VariableDefinition,Equals,Number)
|
||||
),Equals,VariableName),
|
||||
VariableDeclaration(let,ObjectPattern(PatternProperty(VariableName,VariableDefinition)),Equals,VariableName))
|
||||
|
||||
# Generators
|
||||
|
||||
function* foo() { yield 1 }
|
||||
|
||||
class B {
|
||||
*method() {}
|
||||
}
|
||||
|
||||
({*x() {}})
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
FunctionDeclaration(function,Star,VariableDefinition,ParamList,Block(
|
||||
ExpressionStatement(YieldExpression(yield,Number)))),
|
||||
ClassDeclaration(class,VariableDefinition,ClassBody(
|
||||
MethodDeclaration(Star,PropertyDefinition,ParamList,Block))),
|
||||
ExpressionStatement(ParenthesizedExpression(ObjectExpression(Property(Star,PropertyDefinition,ParamList,Block)))))
|
||||
17
node_modules/@lezer/javascript/test/test-javascript.js
generated
vendored
Normal file
17
node_modules/@lezer/javascript/test/test-javascript.js
generated
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
import {parser} from "../dist/index.js"
|
||||
import {fileTests} from "@lezer/generator/dist/test"
|
||||
|
||||
import * as fs from "fs"
|
||||
import * as path from "path"
|
||||
import {fileURLToPath} from "url"
|
||||
let caseDir = path.dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
for (let file of fs.readdirSync(caseDir)) {
|
||||
if (!/\.txt$/.test(file)) continue
|
||||
|
||||
let name = /^[^\.]*/.exec(file)[0]
|
||||
describe(name, () => {
|
||||
for (let {name, run} of fileTests(fs.readFileSync(path.join(caseDir, file), "utf8"), file))
|
||||
it(name, () => run(parser))
|
||||
})
|
||||
}
|
||||
286
node_modules/@lezer/javascript/test/typescript.txt
generated
vendored
Normal file
286
node_modules/@lezer/javascript/test/typescript.txt
generated
vendored
Normal file
@ -0,0 +1,286 @@
|
||||
# Undefined and Null Type {"dialect": "ts"}
|
||||
|
||||
let x: undefined
|
||||
let y: null
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
VariableDeclaration(let,VariableDefinition,TypeAnnotation(
|
||||
TypeName)),
|
||||
VariableDeclaration(let,VariableDefinition,TypeAnnotation(
|
||||
NullType(null))))
|
||||
|
||||
# Type declaration {"dialect": "ts"}
|
||||
|
||||
function foo(a: number, b: "literal" | Map<number, boolean>): RegExp[] {}
|
||||
|
||||
==>
|
||||
|
||||
Script(FunctionDeclaration(function, VariableDefinition, ParamList(
|
||||
VariableDefinition, TypeAnnotation(TypeName),
|
||||
VariableDefinition, TypeAnnotation(UnionType(LiteralType(String), LogicOp, ParameterizedType(TypeName, TypeArgList(TypeName, TypeName))))
|
||||
), TypeAnnotation(ArrayType(TypeName)), Block))
|
||||
|
||||
# Type predicate {"dialect": "ts"}
|
||||
|
||||
function isFoo(foo: any): foo is Foo { return true }
|
||||
|
||||
==>
|
||||
|
||||
Script(FunctionDeclaration(function, VariableDefinition, ParamList(
|
||||
VariableDefinition, TypeAnnotation(TypeName)
|
||||
), TypePredicate(VariableName, is, TypeName), Block(ReturnStatement(return, BooleanLiteral))))
|
||||
|
||||
# Type alias {"dialect": "ts"}
|
||||
|
||||
type Foo<T extends string> = T[]
|
||||
|
||||
==>
|
||||
|
||||
Script(TypeAliasDeclaration(type, TypeDefinition, TypeParamList(TypeDefinition, extends, TypeName), Equals, ArrayType(TypeName)))
|
||||
|
||||
# Enum declaration {"dialect": "ts"}
|
||||
|
||||
const enum Type { Red = 1, Blue, Green }
|
||||
|
||||
==>
|
||||
|
||||
Script(EnumDeclaration(const, enum, TypeDefinition, EnumBody(PropertyName, Equals, Number, PropertyName, PropertyName)))
|
||||
|
||||
# Interface declaration {"dialect": "ts"}
|
||||
|
||||
interface Foo {
|
||||
readonly a: number
|
||||
b(arg: string): void
|
||||
(call: number): boolean
|
||||
new (): Foo
|
||||
readonly [x: string]: number
|
||||
}
|
||||
|
||||
==>
|
||||
|
||||
Script(InterfaceDeclaration(interface, TypeDefinition, ObjectType(
|
||||
PropertyType(readonly, PropertyDefinition, TypeAnnotation(TypeName)),
|
||||
MethodType(PropertyDefinition, ParamList(VariableDefinition, TypeAnnotation(TypeName)), TypeAnnotation(VoidType(void))),
|
||||
CallSignature(ParamList(VariableDefinition, TypeAnnotation(TypeName)), TypeAnnotation(TypeName)),
|
||||
NewSignature(new,ParamList, TypeAnnotation(TypeName)),
|
||||
IndexSignature(readonly, PropertyDefinition, TypeAnnotation(TypeName), TypeAnnotation(TypeName)))))
|
||||
|
||||
# Call type args {"dialect": "ts"}
|
||||
|
||||
foo<number, string>() + new Bar<11>()
|
||||
x < 10 > 5
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
ExpressionStatement(BinaryExpression(
|
||||
CallExpression(VariableName, TypeArgList(TypeName, TypeName), ArgList),
|
||||
ArithOp,
|
||||
NewExpression(new, VariableName, TypeArgList(LiteralType(Number)), ArgList))),
|
||||
ExpressionStatement(BinaryExpression(BinaryExpression(VariableName, CompareOp, Number), CompareOp, Number)))
|
||||
|
||||
# Advanced types {"dialect": "ts"}
|
||||
|
||||
let x: typeof X.x | keyof Y & Z["Foo"] | A<string>
|
||||
let tuple: [a, b]
|
||||
let f: (x: number) => boolean
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
VariableDeclaration(let, VariableDefinition, TypeAnnotation(
|
||||
UnionType(UnionType(TypeofType(typeof, MemberExpression(VariableName, PropertyName)), LogicOp,
|
||||
IntersectionType(KeyofType(keyof, TypeName), LogicOp, IndexedType(TypeName, String))),
|
||||
LogicOp, ParameterizedType(TypeName, TypeArgList(TypeName))))),
|
||||
VariableDeclaration(let, VariableDefinition, TypeAnnotation(TupleType(TypeName, TypeName))),
|
||||
VariableDeclaration(let, VariableDefinition, TypeAnnotation(FunctionSignature(
|
||||
ParamList(VariableDefinition, TypeAnnotation(TypeName)), Arrow, TypeName))))
|
||||
|
||||
# Prefix cast {"dialect": "ts"}
|
||||
|
||||
<string>foo
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(PrefixCast(TypeName, VariableName)))
|
||||
|
||||
# No prefix cast in JSX {"dialect": "ts jsx"}
|
||||
|
||||
<string>foo</string>
|
||||
|
||||
==>
|
||||
|
||||
Script(ExpressionStatement(JSXElement(
|
||||
JSXOpenTag(JSXStartTag, JSXBuiltin(JSXIdentifier), JSXEndTag),
|
||||
JSXText,
|
||||
JSXCloseTag(JSXStartCloseTag, JSXBuiltin(JSXIdentifier), JSXEndTag))))
|
||||
|
||||
# Class definition {"dialect": "ts"}
|
||||
|
||||
class Foo<T> extends Bar<T> implements Stuff {
|
||||
a: number
|
||||
public readonly b: string = "two"
|
||||
constructor(readonly x: boolean, public y: number, z: string) {}
|
||||
private static blah(): void {}
|
||||
}
|
||||
|
||||
==>
|
||||
|
||||
Script(ClassDeclaration(
|
||||
class, VariableDefinition, TypeParamList(TypeDefinition),
|
||||
extends, VariableName, TypeArgList(TypeName),
|
||||
implements TypeName,
|
||||
ClassBody(
|
||||
PropertyDeclaration(PropertyDefinition, TypeAnnotation(TypeName)),
|
||||
PropertyDeclaration(Privacy, readonly, PropertyDefinition, TypeAnnotation(TypeName), Equals, String),
|
||||
MethodDeclaration(PropertyDefinition, ParamList(
|
||||
readonly, VariableDefinition, TypeAnnotation(TypeName),
|
||||
Privacy, VariableDefinition, TypeAnnotation(TypeName),
|
||||
VariableDefinition, TypeAnnotation(TypeName)), Block),
|
||||
MethodDeclaration(Privacy, static, PropertyDefinition, ParamList, TypeAnnotation(VoidType(void)), Block))))
|
||||
|
||||
# Arrow with type params {"dialect": "ts"}
|
||||
|
||||
let x = <T>(arg: T): T => arg
|
||||
|
||||
==>
|
||||
|
||||
Script(VariableDeclaration(let, VariableDefinition, Equals, ArrowFunction(
|
||||
TypeParamList(TypeDefinition),
|
||||
ParamList(VariableDefinition, TypeAnnotation(TypeName)),
|
||||
TypeAnnotation(TypeName),
|
||||
Arrow,
|
||||
VariableName)))
|
||||
|
||||
# Template types {"dialect": "ts"}
|
||||
|
||||
type Tmpl<T> = `${string} ${5}` | `one ${Two}`
|
||||
|
||||
==>
|
||||
|
||||
Script(TypeAliasDeclaration(type, TypeDefinition, TypeParamList(TypeDefinition), Equals,
|
||||
UnionType(TemplateType(Interpolation(InterpolationStart,TypeName,InterpolationEnd), Interpolation(InterpolationStart,LiteralType(Number),InterpolationEnd)), LogicOp, TemplateType(Interpolation(InterpolationStart,TypeName,InterpolationEnd)))))
|
||||
|
||||
# Extending complex types {"dialect": "ts"}
|
||||
|
||||
class Foo extends A.B<Param> {}
|
||||
|
||||
==>
|
||||
|
||||
Script(ClassDeclaration(class, VariableDefinition,
|
||||
extends, MemberExpression(VariableName, PropertyName), TypeArgList(TypeName),
|
||||
ClassBody))
|
||||
|
||||
# Object type {"dialect": "ts"}
|
||||
|
||||
type A = {a: number, b: number}
|
||||
type B = {a: number; b: number;}
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
TypeAliasDeclaration(type,TypeDefinition,Equals,ObjectType(
|
||||
PropertyType(PropertyDefinition,TypeAnnotation(TypeName)),
|
||||
PropertyType(PropertyDefinition,TypeAnnotation(TypeName)))),
|
||||
TypeAliasDeclaration(type,TypeDefinition,Equals,ObjectType(
|
||||
PropertyType(PropertyDefinition,TypeAnnotation(TypeName)),
|
||||
PropertyType(PropertyDefinition,TypeAnnotation(TypeName)))))
|
||||
|
||||
# Conditional Type {"dialect": "ts"}
|
||||
|
||||
type X<T> = T extends E ? number : A
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
TypeAliasDeclaration(type,TypeDefinition,TypeParamList(TypeDefinition),Equals,
|
||||
ConditionalType(TypeName,extends,TypeName,LogicOp,TypeName,LogicOp,TypeName)))
|
||||
|
||||
# Generic Function Type {"dialect": "ts"}
|
||||
|
||||
let f: <T>() => T
|
||||
|
||||
==>
|
||||
|
||||
Script(
|
||||
VariableDeclaration(let,VariableDefinition,TypeAnnotation(
|
||||
FunctionSignature(TypeParamList(TypeDefinition),ParamList,Arrow,TypeName))))
|
||||
|
||||
# Satisfies operator {"dialect": "ts"}
|
||||
|
||||
let x = 1 satisfies number
|
||||
|
||||
==>
|
||||
|
||||
Script(VariableDeclaration(let,VariableDefinition,Equals,BinaryExpression(Number,satisfies,TypeName)))
|
||||
|
||||
# Override modifier on properties {"dialect": "ts"}
|
||||
|
||||
class A {
|
||||
override accessor a;
|
||||
static override b = 1;
|
||||
override c = 2;
|
||||
}
|
||||
|
||||
==>
|
||||
|
||||
Script(ClassDeclaration(class,VariableDefinition,ClassBody(
|
||||
PropertyDeclaration(override,accessor,PropertyDefinition),
|
||||
PropertyDeclaration(static,override,PropertyDefinition,Equals,Number),
|
||||
PropertyDeclaration(override,PropertyDefinition,Equals,Number))))
|
||||
|
||||
# Class extending expression {"dialect": "ts"}
|
||||
|
||||
class X extends class {} {}
|
||||
|
||||
==>
|
||||
|
||||
Script(ClassDeclaration(class,VariableDefinition,extends,ClassExpression(class,ClassBody),ClassBody))
|
||||
|
||||
# Declare syntax {"dialect": "ts"}
|
||||
|
||||
declare namespace myLib {
|
||||
function makeGreeting(s: string): string;
|
||||
let numberOfGreetings: number;
|
||||
}
|
||||
|
||||
declare function greet(setting: GreetingSettings): void;
|
||||
|
||||
declare class Greeter {
|
||||
constructor(greeting: string);
|
||||
greeting: string;
|
||||
showGreeting(): void;
|
||||
}
|
||||
|
||||
class X {
|
||||
declare foo();
|
||||
declare bar: number;
|
||||
}
|
||||
|
||||
==>
|
||||
|
||||
|
||||
Script(
|
||||
AmbientDeclaration(declare,NamespaceDeclaration(namespace,VariableDefinition,Block(
|
||||
FunctionDeclaration(function,VariableDefinition,ParamList(VariableDefinition,TypeAnnotation(TypeName)),
|
||||
TypeAnnotation(TypeName)),
|
||||
VariableDeclaration(let,VariableDefinition,TypeAnnotation(TypeName))))),
|
||||
AmbientDeclaration(declare,AmbientFunctionDeclaration(function,VariableDefinition,
|
||||
ParamList(VariableDefinition,TypeAnnotation(TypeName)),TypeAnnotation(VoidType(void)))),
|
||||
AmbientDeclaration(declare,ClassDeclaration(class,VariableDefinition,ClassBody(
|
||||
MethodDeclaration(PropertyDefinition,ParamList(VariableDefinition,TypeAnnotation(TypeName))),
|
||||
PropertyDeclaration(PropertyDefinition,TypeAnnotation(TypeName)),
|
||||
MethodDeclaration(PropertyDefinition,ParamList,TypeAnnotation(VoidType(void)))))),
|
||||
ClassDeclaration(class,VariableDefinition,ClassBody(
|
||||
MethodDeclaration(declare,PropertyDefinition,ParamList),
|
||||
PropertyDeclaration(declare,PropertyDefinition,TypeAnnotation(TypeName)))))
|
||||
|
||||
# Declare this in a Function {"dialect": "ts"}
|
||||
|
||||
function foo(this: User) {}
|
||||
|
||||
==>
|
||||
|
||||
Script(FunctionDeclaration(function,VariableDefinition,ParamList(this,TypeAnnotation(TypeName)),Block))
|
||||
Reference in New Issue
Block a user