diff --git a/.changeset/swift-dolphins-complain.md b/.changeset/swift-dolphins-complain.md new file mode 100644 index 00000000..d4863ed2 --- /dev/null +++ b/.changeset/swift-dolphins-complain.md @@ -0,0 +1,5 @@ +--- +"svelte-eslint-parser": minor +--- + +fix: parsing error when use with member expr diff --git a/package.json b/package.json index 491b49db..8ec7c723 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "@types/node": "^18.11.0", "@types/semver": "^7.3.9", "@typescript-eslint/eslint-plugin": "^5.4.0", - "@typescript-eslint/parser": "^5.4.0", + "@typescript-eslint/parser": "~5.43.0", "benchmark": "^2.1.4", "chai": "^4.3.4", "code-red": "^0.2.3", diff --git a/src/ast/html.ts b/src/ast/html.ts index 21766e08..106a1e83 100644 --- a/src/ast/html.ts +++ b/src/ast/html.ts @@ -491,12 +491,30 @@ export type SvelteDirective = | SvelteLetDirective | SvelteRefDirective | SvelteTransitionDirective; -export interface SvelteDirectiveKey extends BaseNode { + +export type SvelteDirectiveKey = + | SvelteDirectiveKeyTextName + | SvelteDirectiveKeyFunctionName + | SvelteDirectiveKeyForEventHandler + | SvelteDirectiveKeyForAction + | SvelteDirectiveKeyForStyleShorthand; +interface BaseSvelteDirectiveKey + extends BaseNode { type: "SvelteDirectiveKey"; - name: ESTree.Identifier | SvelteName; + name: N; modifiers: string[]; parent: SvelteDirective | SvelteStyleDirective; } +export type SvelteDirectiveKeyTextName = BaseSvelteDirectiveKey; +export type SvelteDirectiveKeyFunctionName = + BaseSvelteDirectiveKey; +export type SvelteDirectiveKeyForEventHandler = + BaseSvelteDirectiveKey; +export type SvelteDirectiveKeyForAction = BaseSvelteDirectiveKey< + ESTree.Identifier | ESTree.MemberExpression | SvelteName +>; +export type SvelteDirectiveKeyForStyleShorthand = + BaseSvelteDirectiveKey; interface BaseSvelteDirective extends BaseNode { type: "SvelteDirective"; @@ -506,36 +524,44 @@ interface BaseSvelteDirective extends BaseNode { export interface SvelteActionDirective extends BaseSvelteDirective { kind: "Action"; + key: SvelteDirectiveKeyForAction; expression: null | ESTree.Expression; } export interface SvelteAnimationDirective extends BaseSvelteDirective { kind: "Animation"; + key: SvelteDirectiveKeyFunctionName; expression: null | ESTree.Expression; } export interface SvelteBindingDirective extends BaseSvelteDirective { kind: "Binding"; + key: SvelteDirectiveKeyTextName; shorthand: boolean; expression: null | ESTree.Expression; } export interface SvelteClassDirective extends BaseSvelteDirective { kind: "Class"; + key: SvelteDirectiveKeyTextName; shorthand: boolean; expression: null | ESTree.Expression; } export interface SvelteEventHandlerDirective extends BaseSvelteDirective { kind: "EventHandler"; + key: SvelteDirectiveKeyForEventHandler; expression: null | ESTree.Expression; } export interface SvelteLetDirective extends BaseSvelteDirective { kind: "Let"; + key: SvelteDirectiveKeyTextName; expression: null | ESTree.Pattern; } export interface SvelteRefDirective extends BaseSvelteDirective { kind: "Ref"; + key: SvelteDirectiveKeyTextName; expression: null | ESTree.Expression; } export interface SvelteTransitionDirective extends BaseSvelteDirective { kind: "Transition"; + key: SvelteDirectiveKeyFunctionName; intro: boolean; outro: boolean; expression: null | ESTree.Expression; @@ -547,16 +573,18 @@ export type SvelteStyleDirective = | SvelteStyleDirectiveLongform; interface BaseSvelteStyleDirective extends BaseNode { type: "SvelteStyleDirective"; - key: SvelteDirectiveKey; + key: SvelteDirectiveKeyTextName | SvelteDirectiveKeyForStyleShorthand; value: (SvelteLiteral | SvelteMustacheTagText)[]; parent: SvelteStartTag; } export interface SvelteStyleDirectiveShorthand extends BaseSvelteStyleDirective { + key: SvelteDirectiveKeyForStyleShorthand; shorthand: true; value: []; } export interface SvelteStyleDirectiveLongform extends BaseSvelteStyleDirective { + key: SvelteDirectiveKeyTextName; shorthand: false; value: (SvelteLiteral | SvelteMustacheTagText)[]; } diff --git a/src/parser/converts/attr.ts b/src/parser/converts/attr.ts index 559e97a2..e7e5a7f8 100644 --- a/src/parser/converts/attr.ts +++ b/src/parser/converts/attr.ts @@ -369,7 +369,7 @@ function convertStyleDirective( parent: SvelteStyleDirective["parent"], ctx: Context ): SvelteStyleDirective { - const directive: SvelteStyleDirective = { + const directive: SvelteStyleDirectiveLongform = { type: "SvelteStyleDirective", key: null as any, shorthand: false, @@ -379,20 +379,27 @@ function convertStyleDirective( }; processDirectiveKey(node, directive, ctx); - const keyName = directive.key.name as SvelteName; + const keyName = directive.key.name; if (node.value === true) { - (directive as unknown as SvelteStyleDirectiveShorthand).shorthand = true; - ctx.scriptLet.addExpression(keyName, directive.key, null, (expression) => { - if (expression.type !== "Identifier") { - throw new ParseError( - `Expected JS identifier or attribute value.`, - expression.range![0], - ctx - ); + const shorthandDirective = + directive as unknown as SvelteStyleDirectiveShorthand; + shorthandDirective.shorthand = true; + ctx.scriptLet.addExpression( + keyName, + shorthandDirective.key, + null, + (expression) => { + if (expression.type !== "Identifier") { + throw new ParseError( + `Expected JS identifier or attribute value.`, + expression.range![0], + ctx + ); + } + shorthandDirective.key.name = expression; } - directive.key.name = expression; - }); - return directive; + ); + return shorthandDirective; } ctx.addToken("HTMLIdentifier", { start: keyName.range[0], @@ -426,7 +433,13 @@ function convertTransitionDirective( ctx, null ), - processName: (name) => ctx.scriptLet.addExpression(name, directive.key), + processName: (name) => + ctx.scriptLet.addExpression( + name, + directive.key, + null, + buildExpressionTypeChecker(["Identifier"], ctx) + ), }); return directive; } @@ -451,7 +464,13 @@ function convertAnimationDirective( ctx, null ), - processName: (name) => ctx.scriptLet.addExpression(name, directive.key), + processName: (name) => + ctx.scriptLet.addExpression( + name, + directive.key, + null, + buildExpressionTypeChecker(["Identifier"], ctx) + ), }); return directive; } @@ -476,7 +495,13 @@ function convertActionDirective( ctx, null ), - processName: (name) => ctx.scriptLet.addExpression(name, directive.key), + processName: (name) => + ctx.scriptLet.addExpression( + name, + directive.key, + null, + buildExpressionTypeChecker(["Identifier", "MemberExpression"], ctx) + ), }); return directive; } @@ -529,7 +554,7 @@ type DirectiveProcessors< processPattern?: undefined; processName?: ( expression: SvelteName - ) => ScriptLetCallback[]; + ) => ScriptLetCallback>[]; } | { processExpression?: undefined; @@ -539,7 +564,7 @@ type DirectiveProcessors< ) => ScriptLetCallback>[]; processName?: ( expression: SvelteName - ) => ScriptLetCallback[]; + ) => ScriptLetCallback>[]; }; /** Common process for directive */ @@ -658,9 +683,6 @@ function processDirectiveExpression< if (!shorthand) { if (processors.processName) { processors.processName(keyName).push((es) => { - if (es.type !== "Identifier") { - throw new ParseError(`Expected JS identifier.`, es.range![0], ctx); - } key.name = es; }); } else { @@ -682,3 +704,19 @@ function buildProcessExpressionForExpression( return ctx.scriptLet.addExpression(expression, directive, typing); }; } + +/** Build expression type checker to script let callbacks */ +function buildExpressionTypeChecker( + expected: T["type"][], + ctx: Context +): ScriptLetCallback { + return (node) => { + if (!expected.includes(node.type)) { + throw new ParseError( + `Expected JS ${expected.join(", or ")}, but ${node.type} found.`, + node.range![0], + ctx + ); + } + }; +} diff --git a/tests/fixtures/parser/ast/directive-on-with-expr-like-input.svelte b/tests/fixtures/parser/ast/directive-on-with-expr-like-input.svelte new file mode 100644 index 00000000..8be953de --- /dev/null +++ b/tests/fixtures/parser/ast/directive-on-with-expr-like-input.svelte @@ -0,0 +1,8 @@ + + + + + diff --git a/tests/fixtures/parser/ast/directive-on-with-expr-like-no-unused-vars-result.json b/tests/fixtures/parser/ast/directive-on-with-expr-like-no-unused-vars-result.json new file mode 100644 index 00000000..7f794a53 --- /dev/null +++ b/tests/fixtures/parser/ast/directive-on-with-expr-like-no-unused-vars-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "no-unused-vars", + "code": "foo", + "line": 3, + "column": 8 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/directive-on-with-expr-like-output.json b/tests/fixtures/parser/ast/directive-on-with-expr-like-output.json new file mode 100644 index 00000000..8c8dec1a --- /dev/null +++ b/tests/fixtures/parser/ast/directive-on-with-expr-like-output.json @@ -0,0 +1,1230 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + "body": [ + { + "type": "ImportDeclaration", + "source": { + "type": "Literal", + "raw": "'./Inner.svelte'", + "value": "./Inner.svelte", + "range": [ + 28, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 35 + } + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Inner", + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 13 + } + } + } + ], + "range": [ + 10, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 35 + } + } + }, + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + "init": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "bar", + "range": [ + 60, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + "method": false, + "shorthand": false, + "value": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "CallExpression", + "arguments": [ + { + "type": "Literal", + "raw": "'foo.bar'", + "value": "foo.bar", + "range": [ + 77, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 41 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "alert", + "range": [ + 71, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 31 + } + } + }, + "optional": false, + "range": [ + 71, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 42 + } + } + }, + "expression": true, + "generator": false, + "id": null, + "params": [], + "range": [ + 65, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 42 + } + } + }, + "range": [ + 60, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 42 + } + } + } + ], + "range": [ + 58, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 44 + } + } + }, + "range": [ + 52, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 44 + } + } + } + ], + "range": [ + 46, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 44 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 90, + 99 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + "range": [ + 0, + 99 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 99, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "component", + "name": { + "type": "Identifier", + "name": "Inner", + "range": [ + 102, + 107 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "EventHandler", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "foo.bar", + "range": [ + 111, + 118 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 17 + } + } + }, + "modifiers": [], + "range": [ + 108, + 118 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 17 + } + } + }, + "expression": null, + "range": [ + 108, + 118 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 17 + } + } + } + ], + "selfClosing": true, + "range": [ + 101, + 120 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 101, + 120 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + { + "type": "SvelteText", + "value": " ", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + { + "type": "SvelteHTMLComment", + "value": " bubble (not member) ", + "range": [ + 121, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 48 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 149, + 151 + ], + "loc": { + "start": { + "line": 6, + "column": 48 + }, + "end": { + "line": 8, + "column": 0 + } + } + }, + { + "type": "SvelteHTMLComment", + "value": " https://svelte.dev/repl/d6f31e9c5b784f8bb6bc3abd2c7153a7?version=3.52.0 ", + "range": [ + 151, + 231 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 80 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Keyword", + "value": "import", + "range": [ + 10, + 16 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "Inner", + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "from", + "range": [ + 23, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + { + "type": "String", + "value": "'./Inner.svelte'", + "range": [ + 28, + 44 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 35 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 46, + 51 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 58, + 59 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 60, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 66, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 68, + 70 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Identifier", + "value": "alert", + "range": [ + 71, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 3, + "column": 31 + }, + "end": { + "line": 3, + "column": 32 + } + } + }, + { + "type": "String", + "value": "'foo.bar'", + "range": [ + 77, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 41 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 41 + }, + "end": { + "line": 3, + "column": 42 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 43 + }, + "end": { + "line": 3, + "column": 44 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 92, + 98 + ], + "loc": { + "start": { + "line": 4, + "column": 2 + }, + "end": { + "line": 4, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 99, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 9 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + { + "type": "Identifier", + "value": "Inner", + "range": [ + 102, + 107 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "on", + "range": [ + 108, + 110 + ], + "loc": { + "start": { + "line": 6, + "column": 7 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 110, + 111 + ], + "loc": { + "start": { + "line": 6, + "column": 9 + }, + "end": { + "line": 6, + "column": 10 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "foo.bar", + "range": [ + 111, + 118 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 119, + 120 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 19 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 120, + 121 + ], + "loc": { + "start": { + "line": 6, + "column": 19 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + { + "type": "HTMLComment", + "value": "", + "range": [ + 121, + 149 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 48 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 149, + 151 + ], + "loc": { + "start": { + "line": 6, + "column": 48 + }, + "end": { + "line": 8, + "column": 0 + } + } + }, + { + "type": "HTMLComment", + "value": "", + "range": [ + 151, + 231 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 80 + } + } + } + ], + "range": [ + 0, + 232 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/directive-on-with-expr-like-scope-output.json b/tests/fixtures/parser/ast/directive-on-with-expr-like-scope-output.json new file mode 100644 index 00000000..4547a110 --- /dev/null +++ b/tests/fixtures/parser/ast/directive-on-with-expr-like-scope-output.json @@ -0,0 +1,603 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "Inner", + "identifiers": [ + { + "type": "Identifier", + "name": "Inner", + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 13 + } + } + } + ], + "defs": [ + { + "type": "ImportBinding", + "name": { + "type": "Identifier", + "name": "Inner", + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + "node": { + "type": "ImportDefaultSpecifier", + "local": { + "type": "Identifier", + "name": "Inner", + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 13 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "Inner", + "range": [ + 102, + 107 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Inner", + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 13 + } + } + } + } + ] + }, + { + "name": "foo", + "identifiers": [ + { + "type": "Identifier", + "name": "foo", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 10 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "foo", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + "init": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "bar", + "range": [ + 60, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + "method": false, + "shorthand": false, + "value": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "CallExpression", + "arguments": [ + { + "type": "Literal", + "raw": "'foo.bar'", + "value": "foo.bar", + "range": [ + 77, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 32 + }, + "end": { + "line": 3, + "column": 41 + } + } + } + ], + "callee": { + "type": "Identifier", + "name": "alert", + "range": [ + 71, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 31 + } + } + }, + "optional": false, + "range": [ + 71, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 42 + } + } + }, + "expression": true, + "generator": false, + "id": null, + "params": [], + "range": [ + 65, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 42 + } + } + }, + "range": [ + 60, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 15 + }, + "end": { + "line": 3, + "column": 42 + } + } + } + ], + "range": [ + 58, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 44 + } + } + }, + "range": [ + 52, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 44 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "foo", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "foo", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 10 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "foo", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "foo", + "range": [ + 52, + 55 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 10 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "Inner", + "range": [ + 102, + 107 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 6 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "Inner", + "range": [ + 17, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 13 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "alert", + "range": [ + 71, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 31 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "alert", + "range": [ + 71, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 31 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "alert", + "range": [ + 71, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 31 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "alert", + "range": [ + 71, + 76 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 31 + } + } + }, + "from": "function", + "init": null, + "resolved": null + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/directive-use-with-expr-input.svelte b/tests/fixtures/parser/ast/directive-use-with-expr-input.svelte new file mode 100644 index 00000000..c31cab54 --- /dev/null +++ b/tests/fixtures/parser/ast/directive-use-with-expr-input.svelte @@ -0,0 +1,10 @@ + +
+ + diff --git a/tests/fixtures/parser/ast/directive-use-with-expr-output.json b/tests/fixtures/parser/ast/directive-use-with-expr-output.json new file mode 100644 index 00000000..77b32d18 --- /dev/null +++ b/tests/fixtures/parser/ast/directive-use-with-expr-output.json @@ -0,0 +1,1248 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteScriptElement", + "name": { + "type": "SvelteName", + "name": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [], + "selfClosing": false, + "range": [ + 0, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + "body": [ + { + "type": "VariableDeclaration", + "kind": "const", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "init": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "bar", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + } + }, + "method": false, + "shorthand": false, + "value": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "left": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "node", + "range": [ + 52, + 56 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "textContent", + "range": [ + 57, + 68 + ], + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 24 + } + } + }, + "range": [ + 52, + 68 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 24 + } + } + }, + "operator": "=", + "right": { + "type": "Literal", + "raw": "'Success'", + "value": "Success", + "range": [ + 71, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 4, + "column": 36 + } + } + }, + "range": [ + 52, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 36 + } + } + }, + "range": [ + 52, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 36 + } + } + } + ], + "range": [ + 42, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "node", + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 14 + } + } + } + ], + "range": [ + 32, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + "range": [ + 27, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + } + } + ], + "range": [ + 21, + 88 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + "range": [ + 15, + 88 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 6, + "column": 1 + } + } + } + ], + "range": [ + 9, + 88 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 89, + 98 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + "range": [ + 0, + 98 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 8, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 100, + 103 + ], + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Action", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "foo", + "range": [ + 108, + 111 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 12 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "bar", + "range": [ + 112, + 115 + ], + "loc": { + "start": { + "line": 8, + "column": 13 + }, + "end": { + "line": 8, + "column": 16 + } + } + }, + "range": [ + 108, + 115 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 16 + } + } + }, + "modifiers": [], + "range": [ + 104, + 115 + ], + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 16 + } + } + }, + "expression": null, + "range": [ + 104, + 115 + ], + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 16 + } + } + } + ], + "selfClosing": true, + "range": [ + 99, + 118 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 19 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 99, + 118 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 19 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 118, + 120 + ], + "loc": { + "start": { + "line": 8, + "column": 19 + }, + "end": { + "line": 10, + "column": 0 + } + } + }, + { + "type": "SvelteHTMLComment", + "value": " https://svelte.dev/repl/c0a1754292044af695fc20ee66166f89?version=3.52.0 ", + "range": [ + 120, + 200 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 80 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 7, + 8 + ], + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 8 + } + } + }, + { + "type": "Keyword", + "value": "const", + "range": [ + 9, + 14 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 5 + } + } + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 21, + 22 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": "(", + "range": [ + 32, + 33 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Identifier", + "value": "node", + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": ")", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + } + }, + { + "type": "Punctuator", + "value": "=>", + "range": [ + 39, + 41 + ], + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "Identifier", + "value": "node", + "range": [ + 52, + 56 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "textContent", + "range": [ + 57, + 68 + ], + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 69, + 70 + ], + "loc": { + "start": { + "line": 4, + "column": 25 + }, + "end": { + "line": 4, + "column": 26 + } + } + }, + { + "type": "String", + "value": "'Success'", + "range": [ + 71, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 4, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 85, + 86 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 7, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 7, + "column": 1 + }, + "end": { + "line": 7, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 91, + 97 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 97, + 98 + ], + "loc": { + "start": { + "line": 7, + "column": 8 + }, + "end": { + "line": 7, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 98, + 99 + ], + "loc": { + "start": { + "line": 7, + "column": 9 + }, + "end": { + "line": 8, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 99, + 100 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 100, + 103 + ], + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "use", + "range": [ + 104, + 107 + ], + "loc": { + "start": { + "line": 8, + "column": 5 + }, + "end": { + "line": 8, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 107, + 108 + ], + "loc": { + "start": { + "line": 8, + "column": 8 + }, + "end": { + "line": 8, + "column": 9 + } + } + }, + { + "type": "Identifier", + "value": "foo", + "range": [ + 108, + 111 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 111, + 112 + ], + "loc": { + "start": { + "line": 8, + "column": 12 + }, + "end": { + "line": 8, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "bar", + "range": [ + 112, + 115 + ], + "loc": { + "start": { + "line": 8, + "column": 13 + }, + "end": { + "line": 8, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 8, + "column": 17 + }, + "end": { + "line": 8, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 8, + "column": 18 + }, + "end": { + "line": 8, + "column": 19 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 118, + 120 + ], + "loc": { + "start": { + "line": 8, + "column": 19 + }, + "end": { + "line": 10, + "column": 0 + } + } + }, + { + "type": "HTMLComment", + "value": "", + "range": [ + 120, + 200 + ], + "loc": { + "start": { + "line": 10, + "column": 0 + }, + "end": { + "line": 10, + "column": 80 + } + } + } + ], + "range": [ + 0, + 201 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 11, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/directive-use-with-expr-scope-output.json b/tests/fixtures/parser/ast/directive-use-with-expr-scope-output.json new file mode 100644 index 00000000..b8a8cfb5 --- /dev/null +++ b/tests/fixtures/parser/ast/directive-use-with-expr-scope-output.json @@ -0,0 +1,813 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "foo", + "identifiers": [ + { + "type": "Identifier", + "name": "foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "init": { + "type": "ObjectExpression", + "properties": [ + { + "type": "Property", + "kind": "init", + "computed": false, + "key": { + "type": "Identifier", + "name": "bar", + "range": [ + 27, + 30 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 7 + } + } + }, + "method": false, + "shorthand": false, + "value": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "left": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "node", + "range": [ + 52, + 56 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "textContent", + "range": [ + 57, + 68 + ], + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 24 + } + } + }, + "range": [ + 52, + 68 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 24 + } + } + }, + "operator": "=", + "right": { + "type": "Literal", + "raw": "'Success'", + "value": "Success", + "range": [ + 71, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 4, + "column": 36 + } + } + }, + "range": [ + 52, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 36 + } + } + }, + "range": [ + 52, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 36 + } + } + } + ], + "range": [ + 42, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "node", + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 14 + } + } + } + ], + "range": [ + 32, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + "range": [ + 27, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + } + } + ], + "range": [ + 21, + 88 + ], + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + "range": [ + 15, + 88 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 6, + "column": 1 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "foo", + "range": [ + 108, + 111 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "foo", + "range": [ + 108, + 111 + ], + "loc": { + "start": { + "line": 8, + "column": 9 + }, + "end": { + "line": 8, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "foo", + "range": [ + 15, + 18 + ], + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 9 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "node", + "identifiers": [ + { + "type": "Identifier", + "name": "node", + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 14 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "node", + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 14 + } + } + }, + "node": { + "type": "ArrowFunctionExpression", + "async": false, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "left": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "node", + "range": [ + 52, + 56 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "textContent", + "range": [ + 57, + 68 + ], + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 24 + } + } + }, + "range": [ + 52, + 68 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 24 + } + } + }, + "operator": "=", + "right": { + "type": "Literal", + "raw": "'Success'", + "value": "Success", + "range": [ + 71, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 4, + "column": 36 + } + } + }, + "range": [ + 52, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 36 + } + } + }, + "range": [ + 52, + 80 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 36 + } + } + } + ], + "range": [ + 42, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 5, + "column": 5 + } + } + }, + "expression": false, + "generator": false, + "id": null, + "params": [ + { + "type": "Identifier", + "name": "node", + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 14 + } + } + } + ], + "range": [ + 32, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 5 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "node", + "range": [ + 52, + 56 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "node", + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 14 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "node", + "range": [ + 52, + 56 + ], + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 12 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "node", + "range": [ + 33, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 14 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/ts-reactive01-input.svelte b/tests/fixtures/parser/ast/ts-reactive01-input.svelte index a358ff42..bd3004ea 100644 --- a/tests/fixtures/parser/ast/ts-reactive01-input.svelte +++ b/tests/fixtures/parser/ast/ts-reactive01-input.svelte @@ -4,8 +4,8 @@ $: y = x $: z = y - $: foo = get + $: getFunction = get -{foo()} +{getFunction()} diff --git a/tests/fixtures/parser/ast/ts-reactive01-output.json b/tests/fixtures/parser/ast/ts-reactive01-output.json index ba1aa44e..e429ef1e 100644 --- a/tests/fixtures/parser/ast/ts-reactive01-output.json +++ b/tests/fixtures/parser/ast/ts-reactive01-output.json @@ -506,10 +506,10 @@ "type": "AssignmentExpression", "left": { "type": "Identifier", - "name": "foo", + "name": "getFunction", "range": [ 101, - 104 + 112 ], "loc": { "start": { @@ -518,7 +518,7 @@ }, "end": { "line": 7, - "column": 10 + "column": 18 } } }, @@ -527,23 +527,23 @@ "type": "Identifier", "name": "get", "range": [ - 107, - 110 + 115, + 118 ], "loc": { "start": { "line": 7, - "column": 13 + "column": 21 }, "end": { "line": 7, - "column": 16 + "column": 24 } } }, "range": [ 101, - 110 + 118 ], "loc": { "start": { @@ -552,13 +552,13 @@ }, "end": { "line": 7, - "column": 16 + "column": 24 } } }, "range": [ 101, - 110 + 118 ], "loc": { "start": { @@ -567,13 +567,13 @@ }, "end": { "line": 7, - "column": 16 + "column": 24 } } }, "range": [ 98, - 110 + 118 ], "loc": { "start": { @@ -582,7 +582,7 @@ }, "end": { "line": 7, - "column": 16 + "column": 24 } } } @@ -590,8 +590,8 @@ "endTag": { "type": "SvelteEndTag", "range": [ - 111, - 120 + 119, + 128 ], "loc": { "start": { @@ -606,7 +606,7 @@ }, "range": [ 0, - 120 + 128 ], "loc": { "start": { @@ -623,8 +623,8 @@ "type": "SvelteText", "value": "\n\n", "range": [ - 120, - 122 + 128, + 130 ], "loc": { "start": { @@ -644,8 +644,8 @@ "type": "SvelteName", "name": "input", "range": [ - 123, - 128 + 131, + 136 ], "loc": { "start": { @@ -667,8 +667,8 @@ "type": "SvelteName", "name": "title", "range": [ - 129, - 134 + 137, + 142 ], "loc": { "start": { @@ -690,8 +690,8 @@ "type": "Identifier", "name": "z", "range": [ - 136, - 137 + 144, + 145 ], "loc": { "start": { @@ -705,8 +705,8 @@ } }, "range": [ - 135, - 138 + 143, + 146 ], "loc": { "start": { @@ -721,8 +721,8 @@ } ], "range": [ - 129, - 138 + 137, + 146 ], "loc": { "start": { @@ -744,8 +744,8 @@ "type": "SvelteName", "name": "value", "range": [ - 144, - 149 + 152, + 157 ], "loc": { "start": { @@ -760,8 +760,8 @@ }, "modifiers": [], "range": [ - 139, - 149 + 147, + 157 ], "loc": { "start": { @@ -778,8 +778,8 @@ "type": "Identifier", "name": "x", "range": [ - 151, - 152 + 159, + 160 ], "loc": { "start": { @@ -794,8 +794,8 @@ }, "shorthand": false, "range": [ - 139, - 153 + 147, + 161 ], "loc": { "start": { @@ -811,8 +811,8 @@ ], "selfClosing": false, "range": [ - 122, - 154 + 130, + 162 ], "loc": { "start": { @@ -828,8 +828,8 @@ "children": [], "endTag": null, "range": [ - 122, - 154 + 130, + 162 ], "loc": { "start": { @@ -846,8 +846,8 @@ "type": "SvelteText", "value": "\n", "range": [ - 154, - 155 + 162, + 163 ], "loc": { "start": { @@ -868,10 +868,10 @@ "arguments": [], "callee": { "type": "Identifier", - "name": "foo", + "name": "getFunction", "range": [ - 156, - 159 + 164, + 175 ], "loc": { "start": { @@ -880,14 +880,14 @@ }, "end": { "line": 11, - "column": 4 + "column": 12 } } }, "optional": false, "range": [ - 156, - 161 + 164, + 177 ], "loc": { "start": { @@ -896,13 +896,13 @@ }, "end": { "line": 11, - "column": 6 + "column": 14 } } }, "range": [ - 155, - 162 + 163, + 178 ], "loc": { "start": { @@ -911,7 +911,7 @@ }, "end": { "line": 11, - "column": 7 + "column": 15 } } } @@ -1479,10 +1479,10 @@ }, { "type": "Identifier", - "value": "foo", + "value": "getFunction", "range": [ 101, - 104 + 112 ], "loc": { "start": { @@ -1491,7 +1491,7 @@ }, "end": { "line": 7, - "column": 10 + "column": 18 } } }, @@ -1499,17 +1499,17 @@ "type": "Punctuator", "value": "=", "range": [ - 105, - 106 + 113, + 114 ], "loc": { "start": { "line": 7, - "column": 11 + "column": 19 }, "end": { "line": 7, - "column": 12 + "column": 20 } } }, @@ -1517,17 +1517,17 @@ "type": "Identifier", "value": "get", "range": [ - 107, - 110 + 115, + 118 ], "loc": { "start": { "line": 7, - "column": 13 + "column": 21 }, "end": { "line": 7, - "column": 16 + "column": 24 } } }, @@ -1535,8 +1535,8 @@ "type": "Punctuator", "value": "<", "range": [ - 111, - 112 + 119, + 120 ], "loc": { "start": { @@ -1553,8 +1553,8 @@ "type": "Punctuator", "value": "/", "range": [ - 112, - 113 + 120, + 121 ], "loc": { "start": { @@ -1571,8 +1571,8 @@ "type": "HTMLIdentifier", "value": "script", "range": [ - 113, - 119 + 121, + 127 ], "loc": { "start": { @@ -1589,8 +1589,8 @@ "type": "Punctuator", "value": ">", "range": [ - 119, - 120 + 127, + 128 ], "loc": { "start": { @@ -1607,8 +1607,8 @@ "type": "HTMLText", "value": "\n\n", "range": [ - 120, - 122 + 128, + 130 ], "loc": { "start": { @@ -1625,8 +1625,8 @@ "type": "Punctuator", "value": "<", "range": [ - 122, - 123 + 130, + 131 ], "loc": { "start": { @@ -1643,8 +1643,8 @@ "type": "HTMLIdentifier", "value": "input", "range": [ - 123, - 128 + 131, + 136 ], "loc": { "start": { @@ -1661,8 +1661,8 @@ "type": "HTMLIdentifier", "value": "title", "range": [ - 129, - 134 + 137, + 142 ], "loc": { "start": { @@ -1679,8 +1679,8 @@ "type": "Punctuator", "value": "=", "range": [ - 134, - 135 + 142, + 143 ], "loc": { "start": { @@ -1697,8 +1697,8 @@ "type": "Punctuator", "value": "{", "range": [ - 135, - 136 + 143, + 144 ], "loc": { "start": { @@ -1715,8 +1715,8 @@ "type": "Identifier", "value": "z", "range": [ - 136, - 137 + 144, + 145 ], "loc": { "start": { @@ -1733,8 +1733,8 @@ "type": "Punctuator", "value": "}", "range": [ - 137, - 138 + 145, + 146 ], "loc": { "start": { @@ -1751,8 +1751,8 @@ "type": "HTMLIdentifier", "value": "bind", "range": [ - 139, - 143 + 147, + 151 ], "loc": { "start": { @@ -1769,8 +1769,8 @@ "type": "Punctuator", "value": ":", "range": [ - 143, - 144 + 151, + 152 ], "loc": { "start": { @@ -1787,8 +1787,8 @@ "type": "HTMLIdentifier", "value": "value", "range": [ - 144, - 149 + 152, + 157 ], "loc": { "start": { @@ -1805,8 +1805,8 @@ "type": "Punctuator", "value": "=", "range": [ - 149, - 150 + 157, + 158 ], "loc": { "start": { @@ -1823,8 +1823,8 @@ "type": "Punctuator", "value": "{", "range": [ - 150, - 151 + 158, + 159 ], "loc": { "start": { @@ -1841,8 +1841,8 @@ "type": "Identifier", "value": "x", "range": [ - 151, - 152 + 159, + 160 ], "loc": { "start": { @@ -1859,8 +1859,8 @@ "type": "Punctuator", "value": "}", "range": [ - 152, - 153 + 160, + 161 ], "loc": { "start": { @@ -1877,8 +1877,8 @@ "type": "Punctuator", "value": ">", "range": [ - 153, - 154 + 161, + 162 ], "loc": { "start": { @@ -1895,8 +1895,8 @@ "type": "HTMLText", "value": "\n", "range": [ - 154, - 155 + 162, + 163 ], "loc": { "start": { @@ -1913,8 +1913,8 @@ "type": "Punctuator", "value": "{", "range": [ - 155, - 156 + 163, + 164 ], "loc": { "start": { @@ -1929,10 +1929,10 @@ }, { "type": "Identifier", - "value": "foo", + "value": "getFunction", "range": [ - 156, - 159 + 164, + 175 ], "loc": { "start": { @@ -1941,7 +1941,7 @@ }, "end": { "line": 11, - "column": 4 + "column": 12 } } }, @@ -1949,17 +1949,17 @@ "type": "Punctuator", "value": "(", "range": [ - 159, - 160 + 175, + 176 ], "loc": { "start": { "line": 11, - "column": 4 + "column": 12 }, "end": { "line": 11, - "column": 5 + "column": 13 } } }, @@ -1967,17 +1967,17 @@ "type": "Punctuator", "value": ")", "range": [ - 160, - 161 + 176, + 177 ], "loc": { "start": { "line": 11, - "column": 5 + "column": 13 }, "end": { "line": 11, - "column": 6 + "column": 14 } } }, @@ -1985,24 +1985,24 @@ "type": "Punctuator", "value": "}", "range": [ - 161, - 162 + 177, + 178 ], "loc": { "start": { "line": 11, - "column": 6 + "column": 14 }, "end": { "line": 11, - "column": 7 + "column": 15 } } } ], "range": [ 0, - 163 + 179 ], "loc": { "start": { diff --git a/tests/fixtures/parser/ast/ts-reactive01-scope-output.json b/tests/fixtures/parser/ast/ts-reactive01-scope-output.json index b056c53e..9c6fd1e3 100644 --- a/tests/fixtures/parser/ast/ts-reactive01-scope-output.json +++ b/tests/fixtures/parser/ast/ts-reactive01-scope-output.json @@ -8526,8 +8526,8 @@ "type": "Identifier", "name": "x", "range": [ - 151, - 152 + 159, + 160 ], "loc": { "start": { @@ -8730,17 +8730,17 @@ "type": "Identifier", "name": "get", "range": [ - 107, - 110 + 115, + 118 ], "loc": { "start": { "line": 7, - "column": 13 + "column": 21 }, "end": { "line": 7, - "column": 16 + "column": 24 } } }, @@ -9014,8 +9014,8 @@ "type": "Identifier", "name": "z", "range": [ - 136, - 137 + 144, + 145 ], "loc": { "start": { @@ -9052,14 +9052,14 @@ ] }, { - "name": "foo", + "name": "getFunction", "identifiers": [ { "type": "Identifier", - "name": "foo", + "name": "getFunction", "range": [ 101, - 104 + 112 ], "loc": { "start": { @@ -9068,7 +9068,7 @@ }, "end": { "line": 7, - "column": 10 + "column": 18 } } } @@ -9078,10 +9078,10 @@ "type": "ComputedVariable", "name": { "type": "Identifier", - "name": "foo", + "name": "getFunction", "range": [ 101, - 104 + 112 ], "loc": { "start": { @@ -9090,7 +9090,7 @@ }, "end": { "line": 7, - "column": 10 + "column": 18 } } }, @@ -9098,10 +9098,10 @@ "type": "AssignmentExpression", "left": { "type": "Identifier", - "name": "foo", + "name": "getFunction", "range": [ 101, - 104 + 112 ], "loc": { "start": { @@ -9110,7 +9110,7 @@ }, "end": { "line": 7, - "column": 10 + "column": 18 } } }, @@ -9119,23 +9119,23 @@ "type": "Identifier", "name": "get", "range": [ - 107, - 110 + 115, + 118 ], "loc": { "start": { "line": 7, - "column": 13 + "column": 21 }, "end": { "line": 7, - "column": 16 + "column": 24 } } }, "range": [ 101, - 110 + 118 ], "loc": { "start": { @@ -9144,7 +9144,7 @@ }, "end": { "line": 7, - "column": 16 + "column": 24 } } } @@ -9154,10 +9154,10 @@ { "identifier": { "type": "Identifier", - "name": "foo", + "name": "getFunction", "range": [ - 156, - 159 + 164, + 175 ], "loc": { "start": { @@ -9166,7 +9166,7 @@ }, "end": { "line": 11, - "column": 4 + "column": 12 } } }, @@ -9174,10 +9174,10 @@ "init": null, "resolved": { "type": "Identifier", - "name": "foo", + "name": "getFunction", "range": [ 101, - 104 + 112 ], "loc": { "start": { @@ -9186,7 +9186,7 @@ }, "end": { "line": 7, - "column": 10 + "column": 18 } } } @@ -9438,10 +9438,10 @@ { "identifier": { "type": "Identifier", - "name": "foo", + "name": "getFunction", "range": [ 101, - 104 + 112 ], "loc": { "start": { @@ -9450,7 +9450,7 @@ }, "end": { "line": 7, - "column": 10 + "column": 18 } } }, @@ -9458,10 +9458,10 @@ "init": false, "resolved": { "type": "Identifier", - "name": "foo", + "name": "getFunction", "range": [ 101, - 104 + 112 ], "loc": { "start": { @@ -9470,7 +9470,7 @@ }, "end": { "line": 7, - "column": 10 + "column": 18 } } } @@ -9480,17 +9480,17 @@ "type": "Identifier", "name": "get", "range": [ - 107, - 110 + 115, + 118 ], "loc": { "start": { "line": 7, - "column": 13 + "column": 21 }, "end": { "line": 7, - "column": 16 + "column": 24 } } }, @@ -9520,8 +9520,8 @@ "type": "Identifier", "name": "z", "range": [ - 136, - 137 + 144, + 145 ], "loc": { "start": { @@ -9560,8 +9560,8 @@ "type": "Identifier", "name": "x", "range": [ - 151, - 152 + 159, + 160 ], "loc": { "start": { @@ -9598,10 +9598,10 @@ { "identifier": { "type": "Identifier", - "name": "foo", + "name": "getFunction", "range": [ - 156, - 159 + 164, + 175 ], "loc": { "start": { @@ -9610,7 +9610,7 @@ }, "end": { "line": 11, - "column": 4 + "column": 12 } } }, @@ -9618,10 +9618,10 @@ "init": null, "resolved": { "type": "Identifier", - "name": "foo", + "name": "getFunction", "range": [ 101, - 104 + 112 ], "loc": { "start": { @@ -9630,7 +9630,7 @@ }, "end": { "line": 7, - "column": 10 + "column": 18 } } } diff --git a/tests/fixtures/parser/ast/ts-reactive01-type-output.svelte b/tests/fixtures/parser/ast/ts-reactive01-type-output.svelte index 745f751d..60c62035 100644 --- a/tests/fixtures/parser/ast/ts-reactive01-type-output.svelte +++ b/tests/fixtures/parser/ast/ts-reactive01-type-output.svelte @@ -4,8 +4,8 @@ $: y = x // $: any, y: string, x: string $: z = y // $: any, z: string, y: string - $: foo = get // $: any, foo: () => string, get: () => string + $: getFunction = get // $: any, getFunction: () => string, get: () => string -{foo()} +{getFunction()} diff --git a/tests/fixtures/parser/error/directive-animate-with-expr-input.svelte b/tests/fixtures/parser/error/directive-animate-with-expr-input.svelte new file mode 100644 index 00000000..81ae38e9 --- /dev/null +++ b/tests/fixtures/parser/error/directive-animate-with-expr-input.svelte @@ -0,0 +1,22 @@ + + +{#each list as item, index (item)} +
  • {item}
  • +{/each} + + + + diff --git a/tests/fixtures/parser/error/directive-animate-with-expr-output.json b/tests/fixtures/parser/error/directive-animate-with-expr-output.json new file mode 100644 index 00000000..b8fd547f --- /dev/null +++ b/tests/fixtures/parser/error/directive-animate-with-expr-output.json @@ -0,0 +1,6 @@ +{ + "index": 476, + "lineNumber": 17, + "message": "Expected JS Identifier, but MemberExpression found.", + "column": 13 +} \ No newline at end of file diff --git a/tests/fixtures/parser/error/directive-class-with-expr-input.svelte b/tests/fixtures/parser/error/directive-class-with-expr-input.svelte new file mode 100644 index 00000000..690fa15f --- /dev/null +++ b/tests/fixtures/parser/error/directive-class-with-expr-input.svelte @@ -0,0 +1,7 @@ + +
    A
    +
    A
    + + + + diff --git a/tests/fixtures/parser/error/directive-class-with-expr-output.json b/tests/fixtures/parser/error/directive-class-with-expr-output.json new file mode 100644 index 00000000..eb241c5e --- /dev/null +++ b/tests/fixtures/parser/error/directive-class-with-expr-output.json @@ -0,0 +1,6 @@ +{ + "index": 12, + "lineNumber": 2, + "message": "Expected Identifier, but MemberExpression found.", + "column": 11 +} \ No newline at end of file diff --git a/tests/fixtures/parser/error/directive-in-with-exxpr-input.svelte b/tests/fixtures/parser/error/directive-in-with-exxpr-input.svelte new file mode 100644 index 00000000..5fcc0694 --- /dev/null +++ b/tests/fixtures/parser/error/directive-in-with-exxpr-input.svelte @@ -0,0 +1,20 @@ + + + + +{#if visible} +

    + Flies in, fades out +

    +{/if} + + + + diff --git a/tests/fixtures/parser/error/directive-in-with-exxpr-output.json b/tests/fixtures/parser/error/directive-in-with-exxpr-output.json new file mode 100644 index 00000000..73077a1a --- /dev/null +++ b/tests/fixtures/parser/error/directive-in-with-exxpr-output.json @@ -0,0 +1,6 @@ +{ + "index": 212, + "lineNumber": 13, + "message": "Expected JS Identifier, but MemberExpression found.", + "column": 7 +} \ No newline at end of file diff --git a/tests/fixtures/parser/error/directive-out-with-expr-input.svelte b/tests/fixtures/parser/error/directive-out-with-expr-input.svelte new file mode 100644 index 00000000..ad0e2347 --- /dev/null +++ b/tests/fixtures/parser/error/directive-out-with-expr-input.svelte @@ -0,0 +1,20 @@ + + + + +{#if visible} +

    + Flies in, fades out +

    +{/if} + + + + diff --git a/tests/fixtures/parser/error/directive-out-with-expr-output.json b/tests/fixtures/parser/error/directive-out-with-expr-output.json new file mode 100644 index 00000000..2f83e74b --- /dev/null +++ b/tests/fixtures/parser/error/directive-out-with-expr-output.json @@ -0,0 +1,6 @@ +{ + "index": 213, + "lineNumber": 13, + "message": "Expected JS Identifier, but MemberExpression found.", + "column": 8 +} \ No newline at end of file diff --git a/tests/fixtures/parser/error/directive-style-with-expr-input.svelte b/tests/fixtures/parser/error/directive-style-with-expr-input.svelte new file mode 100644 index 00000000..369d47c1 --- /dev/null +++ b/tests/fixtures/parser/error/directive-style-with-expr-input.svelte @@ -0,0 +1,7 @@ + +
    A
    +
    A
    + + + + diff --git a/tests/fixtures/parser/error/directive-style-with-expr-output.json b/tests/fixtures/parser/error/directive-style-with-expr-output.json new file mode 100644 index 00000000..6eb2f34b --- /dev/null +++ b/tests/fixtures/parser/error/directive-style-with-expr-output.json @@ -0,0 +1,6 @@ +{ + "index": 12, + "lineNumber": 2, + "message": "Expected JS identifier or attribute value.", + "column": 11 +} \ No newline at end of file diff --git a/tests/fixtures/parser/error/directive-transition-with-expr-input.svelte b/tests/fixtures/parser/error/directive-transition-with-expr-input.svelte new file mode 100644 index 00000000..b0eabfeb --- /dev/null +++ b/tests/fixtures/parser/error/directive-transition-with-expr-input.svelte @@ -0,0 +1,20 @@ + + + + +{#if visible} +

    + Fades in and out +

    +{/if} + + + + diff --git a/tests/fixtures/parser/error/directive-transition-with-expr-output.json b/tests/fixtures/parser/error/directive-transition-with-expr-output.json new file mode 100644 index 00000000..7af0229c --- /dev/null +++ b/tests/fixtures/parser/error/directive-transition-with-expr-output.json @@ -0,0 +1,6 @@ +{ + "index": 210, + "lineNumber": 13, + "message": "Expected JS Identifier, but MemberExpression found.", + "column": 15 +} \ No newline at end of file diff --git a/tests/fixtures/parser/error/directive-use-with-expr01-input.svelte b/tests/fixtures/parser/error/directive-use-with-expr01-input.svelte new file mode 100644 index 00000000..9b8cfb08 --- /dev/null +++ b/tests/fixtures/parser/error/directive-use-with-expr01-input.svelte @@ -0,0 +1,11 @@ + + +
    + + + + diff --git a/tests/fixtures/parser/error/directive-use-with-expr01-output.json b/tests/fixtures/parser/error/directive-use-with-expr01-output.json new file mode 100644 index 00000000..96b020d4 --- /dev/null +++ b/tests/fixtures/parser/error/directive-use-with-expr01-output.json @@ -0,0 +1,6 @@ +{ + "index": 117, + "lineNumber": 7, + "message": "Expected JS Identifier, or MemberExpression, but CallExpression found.", + "column": 9 +} \ No newline at end of file diff --git a/tests/fixtures/parser/error/directive-use-with-expr02-input.svelte b/tests/fixtures/parser/error/directive-use-with-expr02-input.svelte new file mode 100644 index 00000000..db2b7c92 --- /dev/null +++ b/tests/fixtures/parser/error/directive-use-with-expr02-input.svelte @@ -0,0 +1,11 @@ + + +
    + + + + diff --git a/tests/fixtures/parser/error/directive-use-with-expr02-output.json b/tests/fixtures/parser/error/directive-use-with-expr02-output.json new file mode 100644 index 00000000..3ff61214 --- /dev/null +++ b/tests/fixtures/parser/error/directive-use-with-expr02-output.json @@ -0,0 +1,6 @@ +{ + "index": 95, + "lineNumber": 7, + "message": "Expected JS Identifier, or MemberExpression, but CallExpression found.", + "column": 9 +} \ No newline at end of file diff --git a/tests/fixtures/parser/error/name01-output.json b/tests/fixtures/parser/error/name01-output.json index 44421403..44d98c95 100644 --- a/tests/fixtures/parser/error/name01-output.json +++ b/tests/fixtures/parser/error/name01-output.json @@ -1,6 +1,6 @@ { "index": 85, "lineNumber": 7, - "message": "Expected JS identifier.", + "message": "Expected JS Identifier, but BinaryExpression found.", "column": 15 } \ No newline at end of file