diff --git a/src/ast.ts b/src/ast.ts index 10d203d3..731de341 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -60,6 +60,7 @@ export type SvelteNode = | SvelteLiteral | SvelteMustacheTag | SvelteDebugTag + | SvelteConstTag | SvelteIfBlock | SvelteElseBlock | SvelteEachBlock @@ -215,6 +216,7 @@ type Child = | SvelteText | SvelteMustacheTag | SvelteDebugTag + | SvelteConstTag | SvelteIfBlockAlone | SvelteEachBlock | SvelteAwaitBlock @@ -241,7 +243,7 @@ export interface SvelteText extends BaseNode { export interface SvelteLiteral extends BaseNode { type: "SvelteLiteral" value: string - parent: SvelteAttribute + parent: SvelteAttribute | SvelteStyleDirective } /** Node of mustache tag. e.g. `{...}`, `{@html ...}`. Like JSXExpressionContainer */ @@ -286,6 +288,22 @@ export interface SvelteDebugTag extends BaseNode { | SvelteKeyBlock | SvelteAttribute } +/** Node of const tag. e.g. `{@const}` */ +export interface SvelteConstTag extends BaseNode { + type: "SvelteConstTag" + declaration: ESTree.VariableDeclarator + parent: + | SvelteProgram + | SvelteElement + | SvelteIfBlock + | SvelteElseBlockAlone + | SvelteEachBlock + | SvelteAwaitPendingBlock + | SvelteAwaitThenBlock + | SvelteAwaitCatchBlock + | SvelteKeyBlock + | SvelteAttribute +} /** Node of if block. e.g. `{#if}` */ export type SvelteIfBlock = SvelteIfBlockAlone | SvelteIfBlockElseIf interface BaseSvelteIfBlock extends BaseNode { @@ -511,6 +529,7 @@ export type SvelteDirective = | SvelteAnimationDirective | SvelteBindingDirective | SvelteClassDirective + | SvelteStyleDirective | SvelteEventHandlerDirective | SvelteLetDirective | SvelteRefDirective @@ -544,6 +563,10 @@ export interface SvelteClassDirective extends BaseSvelteDirective { kind: "Class" expression: null | ESTree.Expression } +export interface SvelteStyleDirective extends BaseSvelteDirective { + kind: "Style" + expression: null | ESTree.Expression | SvelteLiteral +} export interface SvelteEventHandlerDirective extends BaseSvelteDirective { kind: "EventHandler" expression: null | ESTree.Expression diff --git a/src/context/script-let.ts b/src/context/script-let.ts index 4413402e..c1acb5f7 100644 --- a/src/context/script-let.ts +++ b/src/context/script-let.ts @@ -180,6 +180,44 @@ export class ScriptLetContext { return callbacks } + public addVariableDeclarator( + expression: ESTree.AssignmentExpression, + parent: SvelteNode, + ...callbacks: ScriptLetCallback[] + ): ScriptLetCallback[] { + const range = getNodeRange(expression) + const part = this.ctx.code.slice(...range) + this.appendScript( + `const ${part};`, + range[0] - 6, + (st, tokens, _comments, result) => { + const decl = st as ESTree.VariableDeclaration + const node = decl.declarations[0] + // Process for nodes + for (const callback of callbacks) { + callback(node, result) + } + ;(node as any).parent = parent + + const scope = result.getScope(decl) + for (const variable of scope.variables) { + for (const def of variable.defs) { + if (def.parent === decl) { + ;(def as any).parent = parent + } + } + } + + tokens.shift() // const + tokens.pop() // ; + + // Disconnect the tree structure. + decl.declarations = [] + }, + ) + return callbacks + } + public nestIfBlock( expression: ESTree.Expression, ifBlock: SvelteIfBlock, diff --git a/src/parser/converts/attr.ts b/src/parser/converts/attr.ts index 629d821d..68fb5516 100644 --- a/src/parser/converts/attr.ts +++ b/src/parser/converts/attr.ts @@ -12,13 +12,14 @@ import type { SvelteTransitionDirective, SvelteStartTag, SvelteName, + SvelteStyleDirective, } from "../../ast" import type ESTree from "estree" import type { Context } from "../../context" import type * as SvAST from "../svelte-ast-types" import { getWithLoc, indexOf } from "./common" import { convertMustacheTag } from "./mustache" -import { convertTextToLiteral } from "./text" +import { convertTemplateLiteralToLiteral, convertTextToLiteral } from "./text" import { ParseError } from "../../errors" import type { ScriptLetCallback } from "../../context/script-let" @@ -54,6 +55,10 @@ export function* convertAttributes( yield convertClassDirective(attr, parent, ctx) continue } + if (attr.type === "Style") { + yield convertStyleDirective(attr, parent, ctx) + continue + } if (attr.type === "Transition") { yield convertTransitionDirective(attr, parent, ctx) continue @@ -284,6 +289,79 @@ function convertClassDirective( return directive } +/** Convert for Style Directive */ +function convertStyleDirective( + node: SvAST.DirectiveForExpression, + parent: SvelteDirective["parent"], + ctx: Context, +): SvelteStyleDirective { + const directive: SvelteStyleDirective = { + type: "SvelteDirective", + kind: "Style", + key: null as any, + expression: null, + parent, + ...ctx.getConvertLocation(node), + } + if (processStyleDirectiveValue(node, ctx)) { + processDirective(node, directive, ctx, (expression) => { + directive.expression = convertTemplateLiteralToLiteral( + expression, + directive, + ctx, + ) + return [] + }) + } else { + processDirective(node, directive, ctx, (expression) => { + return ctx.scriptLet.addExpression(expression, directive) + }) + } + + return directive +} + +/** Process plain value */ +function processStyleDirectiveValue( + node: SvAST.DirectiveForExpression, + ctx: Context, +): node is SvAST.DirectiveForExpression & { + expression: ESTree.TemplateLiteral +} { + const { expression } = node + if ( + !expression || + expression.type !== "TemplateLiteral" || + expression.expressions.length !== 0 + ) { + return false + } + const quasi = expression.quasis[0] + if (quasi.value.cooked != null) { + return false + } + const eqIndex = ctx.code.indexOf("=", node.start) + if (eqIndex < 0 || eqIndex >= node.end) { + return false + } + const valueIndex = ctx.code.indexOf(quasi.value.raw, eqIndex + 1) + if (valueIndex < 0 || valueIndex >= node.end) { + return false + } + const maybeEnd = valueIndex + quasi.value.raw.length + const maybeOpenQuote = ctx.code.slice(eqIndex + 1, valueIndex).trimStart() + if (maybeOpenQuote && maybeOpenQuote !== '"' && maybeOpenQuote !== "'") { + return false + } + const maybeCloseQuote = ctx.code.slice(maybeEnd, node.end).trimEnd() + if (maybeCloseQuote !== maybeOpenQuote) { + return false + } + getWithLoc(expression).start = valueIndex + getWithLoc(expression).end = maybeEnd + return true +} + /** Convert for Transition Directive */ function convertTransitionDirective( node: SvAST.TransitionDirective, diff --git a/src/parser/converts/const.ts b/src/parser/converts/const.ts new file mode 100644 index 00000000..0efe02e6 --- /dev/null +++ b/src/parser/converts/const.ts @@ -0,0 +1,30 @@ +import type { SvelteConstTag } from "../../ast" +import type { Context } from "../../context" +import type * as SvAST from "../svelte-ast-types" + +/** Convert for ConstTag */ +export function convertConstTag( + node: SvAST.ConstTag, + parent: SvelteConstTag["parent"], + ctx: Context, +): SvelteConstTag { + const mustache: SvelteConstTag = { + type: "SvelteConstTag", + declaration: null as any, + parent, + ...ctx.getConvertLocation(node), + } + ctx.scriptLet.addVariableDeclarator( + node.expression, + mustache, + (declaration) => { + mustache.declaration = declaration + }, + ) + const atConstStart = ctx.code.indexOf("@const", mustache.range[0]) + ctx.addToken("MustacheKeyword", { + start: atConstStart, + end: atConstStart + 6, + }) + return mustache +} diff --git a/src/parser/converts/element.ts b/src/parser/converts/element.ts index b68c85ab..a818d22c 100644 --- a/src/parser/converts/element.ts +++ b/src/parser/converts/element.ts @@ -4,6 +4,7 @@ import type { SvelteAwaitPendingBlock, SvelteAwaitThenBlock, SvelteComponentElement, + SvelteConstTag, SvelteDebugTag, SvelteEachBlock, SvelteElement, @@ -41,6 +42,7 @@ import { } from "./mustache" import { convertText } from "./text" import { convertAttributes } from "./attr" +import { convertConstTag } from "./const" /* eslint-disable complexity -- X */ /** Convert for Fragment or Element or ... */ @@ -63,6 +65,7 @@ export function* convertChildren( | SvelteElement | SvelteMustacheTag | SvelteDebugTag + | SvelteConstTag | SvelteIfBlockAlone | SvelteEachBlock | SvelteAwaitBlock @@ -150,11 +153,27 @@ export function* convertChildren( yield convertDebugTag(child, parent, ctx) continue } + if (child.type === "ConstTag") { + yield convertConstTag(child, parent, ctx) + continue + } throw new Error(`Unknown type:${(child as any).type}`) } } +/** Check if children needs a scope. */ +function needScopeByChildren(fragment: { + children: SvAST.TemplateNode[] +}): boolean { + for (const child of fragment.children) { + if (child.type === "ConstTag") { + return true + } + } + return false +} + /** Convert for HTML Comment */ function convertComment( node: SvAST.Comment, @@ -210,7 +229,7 @@ function convertHTMLElement( ...convertAttributes(node.attributes, element.startTag, ctx), ) const lets = ctx.letDirCollections.extract() - if (lets.isEmpty()) { + if (lets.isEmpty() && !needScopeByChildren(node)) { element.children.push(...convertChildren(node, element, ctx)) } else { ctx.scriptLet.nestBlock( @@ -297,7 +316,7 @@ function convertSpecialElement( ...convertAttributes(node.attributes, element.startTag, ctx), ) const lets = ctx.letDirCollections.extract() - if (lets.isEmpty()) { + if (lets.isEmpty() && !needScopeByChildren(node)) { element.children.push(...convertChildren(node, element, ctx)) } else { ctx.scriptLet.nestBlock( @@ -406,7 +425,7 @@ function convertComponentElement( ...convertAttributes(node.attributes, element.startTag, ctx), ) const lets = ctx.letDirCollections.extract() - if (lets.isEmpty()) { + if (lets.isEmpty() && !needScopeByChildren(node)) { element.children.push(...convertChildren(node, element, ctx)) } else { ctx.scriptLet.nestBlock( diff --git a/src/parser/converts/text.ts b/src/parser/converts/text.ts index 5b6355c6..fbeb372c 100644 --- a/src/parser/converts/text.ts +++ b/src/parser/converts/text.ts @@ -1,6 +1,8 @@ +import type ESTree from "estree" import type { SvelteLiteral, SvelteText } from "../../ast" import type { Context } from "../../context" import type * as SvAST from "../svelte-ast-types" +import { getWithLoc } from "./common" /** Convert for Text */ export function convertText( node: SvAST.Text, @@ -13,20 +15,7 @@ export function convertText( parent, ...ctx.getConvertLocation(node), } - let start = node.start - let word = false - for (let index = node.start; index < node.end; index++) { - if (word !== Boolean(ctx.code[index].trim())) { - if (start < index) { - ctx.addToken("HTMLText", { start, end: index }) - } - word = !word - start = index - } - } - if (start < node.end) { - ctx.addToken("HTMLText", { start, end: node.end }) - } + extractTextTokens(node, ctx) return text } @@ -42,9 +31,34 @@ export function convertTextToLiteral( parent, ...ctx.getConvertLocation(node), } - let start = node.start + extractTextTokens(node, ctx) + return text +} +/** Convert for StyleDir's TemplateLiteral to Literal */ +export function convertTemplateLiteralToLiteral( + node: ESTree.TemplateLiteral, + parent: SvelteLiteral["parent"], + ctx: Context, +): SvelteLiteral { + const text: SvelteLiteral = { + type: "SvelteLiteral", + value: node.quasis[0].value.raw, + parent, + ...ctx.getConvertLocation(node), + } + extractTextTokens(node, ctx) + return text +} + +/** Extract tokens */ +function extractTextTokens( + node: SvAST.Text | ESTree.TemplateLiteral, + ctx: Context, +) { + const loc = getWithLoc(node) + let start = loc.start let word = false - for (let index = node.start; index < node.end; index++) { + for (let index = loc.start; index < loc.end; index++) { if (word !== Boolean(ctx.code[index].trim())) { if (start < index) { ctx.addToken("HTMLText", { start, end: index }) @@ -53,8 +67,7 @@ export function convertTextToLiteral( start = index } } - if (start < node.end) { - ctx.addToken("HTMLText", { start, end: node.end }) + if (start < loc.end) { + ctx.addToken("HTMLText", { start, end: loc.end }) } - return text } diff --git a/src/parser/svelte-ast-types.ts b/src/parser/svelte-ast-types.ts index 0cb5e58e..2946d925 100644 --- a/src/parser/svelte-ast-types.ts +++ b/src/parser/svelte-ast-types.ts @@ -14,6 +14,7 @@ export declare type TemplateNode = | MustacheTag | RawMustacheTag | DebugTag + | ConstTag | Directive | Element | InlineComponent @@ -49,6 +50,10 @@ export interface DebugTag extends BaseNode { type: "DebugTag" identifiers: ESTree.Identifier[] } +export interface ConstTag extends BaseNode { + type: "ConstTag" + expression: ESTree.AssignmentExpression +} export interface IfBlock extends BaseNode { type: "IfBlock" expression: ESTree.Expression @@ -188,7 +193,14 @@ interface BaseDirective extends BaseNode { modifiers: string[] } export interface DirectiveForExpression extends BaseDirective { - type: "Action" | "Animation" | "Binding" | "Class" | "EventHandler" | "Ref" + type: + | "Action" + | "Animation" + | "Binding" + | "Class" + | "Style" + | "EventHandler" + | "Ref" expression: null | ESTree.Expression } export interface LetDirective extends BaseDirective { diff --git a/src/visitor-keys.ts b/src/visitor-keys.ts index da877f93..c9664ad7 100644 --- a/src/visitor-keys.ts +++ b/src/visitor-keys.ts @@ -21,6 +21,7 @@ const svelteKeys: SvelteKeysType = { SvelteLiteral: [], SvelteMustacheTag: ["expression"], SvelteDebugTag: ["identifiers"], + SvelteConstTag: ["declaration"], SvelteIfBlock: ["expression", "children", "else"], SvelteElseBlock: ["children"], SvelteEachBlock: [ diff --git a/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-input.svelte new file mode 100644 index 00000000..9f06048f --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-input.svelte @@ -0,0 +1 @@ +{@const variable = assignment} diff --git a/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-no-undef-result.json b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-no-undef-result.json new file mode 100644 index 00000000..274fc1fb --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-no-undef-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "no-undef", + "code": "assignment", + "line": 1, + "column": 20 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-no-unused-vars-result.json b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-no-unused-vars-result.json new file mode 100644 index 00000000..4251970f --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-no-unused-vars-result.json @@ -0,0 +1,8 @@ +[ + { + "ruleId": "no-unused-vars", + "code": "variable", + "line": 1, + "column": 9 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-output.json b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-output.json new file mode 100644 index 00000000..3df0e787 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-output.json @@ -0,0 +1,201 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteConstTag", + "declaration": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "variable", + "range": [ + 8, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + "init": { + "type": "Identifier", + "name": "assignment", + "range": [ + 19, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + "range": [ + 8, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + "range": [ + 0, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "{", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MustacheKeyword", + "value": "@const", + "range": [ + 1, + 7 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "variable", + "range": [ + 8, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 17, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "assignment", + "range": [ + 19, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + } + } + ], + "range": [ + 0, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-scope-output.json new file mode 100644 index 00000000..da97d137 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/01-scope-output.json @@ -0,0 +1,288 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "variable", + "identifiers": [ + { + "type": "Identifier", + "name": "variable", + "range": [ + 8, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "variable", + "range": [ + 8, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "variable", + "range": [ + 8, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + "init": { + "type": "Identifier", + "name": "assignment", + "range": [ + 19, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + "range": [ + 8, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 29 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "variable", + "range": [ + 8, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "variable", + "range": [ + 8, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "variable", + "range": [ + 8, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + } + }, + "from": "module", + "init": true, + "resolved": { + "type": "Identifier", + "name": "variable", + "range": [ + 8, + 16 + ], + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "assignment", + "range": [ + 19, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "assignment", + "range": [ + 19, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "assignment", + "range": [ + 19, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/02-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/02-input.svelte new file mode 100644 index 00000000..0b433ad6 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/02-input.svelte @@ -0,0 +1,8 @@ + + +{#each boxes as box} + {@const area = box.width * box.height} + {box.width} * {box.height} = {area} +{/each} diff --git a/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/02-output.json b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/02-output.json new file mode 100644 index 00000000..d235c719 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/02-output.json @@ -0,0 +1,1617 @@ +{ + "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": "ExportNamedDeclaration", + "declaration": { + "type": "VariableDeclaration", + "kind": "let", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "boxes", + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "init": null, + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + ], + "range": [ + 18, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "source": null, + "specifiers": [], + "range": [ + 11, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 19 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 29, + 38 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + "range": [ + 0, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 38, + 40 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteEachBlock", + "expression": { + "type": "Identifier", + "name": "boxes", + "range": [ + 47, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "context": { + "type": "Identifier", + "name": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + "index": null, + "key": null, + "children": [ + { + "type": "SvelteConstTag", + "declaration": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "area", + "range": [ + 71, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "init": { + "type": "BinaryExpression", + "left": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "box", + "range": [ + 78, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "width", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + "range": [ + 78, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + "operator": "*", + "right": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "box", + "range": [ + 90, + 93 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 32 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "height", + "range": [ + 94, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 33 + }, + "end": { + "line": 6, + "column": 39 + } + } + }, + "range": [ + 90, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 39 + } + } + }, + "range": [ + 78, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 39 + } + } + }, + "range": [ + 71, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 39 + } + } + }, + "range": [ + 63, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 40 + } + } + }, + { + "type": "SvelteText", + "value": "\n ", + "range": [ + 101, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 40 + }, + "end": { + "line": 7, + "column": 2 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "box", + "range": [ + 105, + 108 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 6 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "width", + "range": [ + 109, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 105, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 104, + 115 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 13 + } + } + }, + { + "type": "SvelteText", + "value": " * ", + "range": [ + 115, + 118 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 16 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "box", + "range": [ + 119, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "height", + "range": [ + 123, + 129 + ], + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 27 + } + } + }, + "range": [ + 119, + 129 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 27 + } + } + }, + "range": [ + 118, + 130 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 28 + } + } + }, + { + "type": "SvelteText", + "value": " = ", + "range": [ + 130, + 133 + ], + "loc": { + "start": { + "line": 7, + "column": 28 + }, + "end": { + "line": 7, + "column": 31 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "area", + "range": [ + 134, + 138 + ], + "loc": { + "start": { + "line": 7, + "column": 32 + }, + "end": { + "line": 7, + "column": 36 + } + } + }, + "range": [ + 133, + 139 + ], + "loc": { + "start": { + "line": 7, + "column": 31 + }, + "end": { + "line": 7, + "column": 37 + } + } + } + ], + "else": null, + "range": [ + 40, + 147 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 8, + "column": 7 + } + } + } + ], + "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": "export", + "range": [ + 11, + 17 + ], + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 8 + } + } + }, + { + "type": "Keyword", + "value": "let", + "range": [ + 18, + 21 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 12 + } + } + }, + { + "type": "Identifier", + "value": "boxes", + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + { + "type": "Punctuator", + "value": ";", + "range": [ + 27, + 28 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 2 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "script", + "range": [ + 31, + 37 + ], + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 8 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 9 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 38, + 40 + ], + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 40, + 41 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 1 + } + } + }, + { + "type": "MustacheKeyword", + "value": "#each", + "range": [ + 41, + 46 + ], + "loc": { + "start": { + "line": 5, + "column": 1 + }, + "end": { + "line": 5, + "column": 6 + } + } + }, + { + "type": "Identifier", + "value": "boxes", + "range": [ + 47, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + { + "type": "Keyword", + "value": "as", + "range": [ + 53, + 55 + ], + "loc": { + "start": { + "line": 5, + "column": 13 + }, + "end": { + "line": 5, + "column": 15 + } + } + }, + { + "type": "Identifier", + "value": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + } + }, + { + "type": "MustacheKeyword", + "value": "@const", + "range": [ + 64, + 70 + ], + "loc": { + "start": { + "line": 6, + "column": 3 + }, + "end": { + "line": 6, + "column": 9 + } + } + }, + { + "type": "Identifier", + "value": "area", + "range": [ + 71, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 76, + 77 + ], + "loc": { + "start": { + "line": 6, + "column": 15 + }, + "end": { + "line": 6, + "column": 16 + } + } + }, + { + "type": "Identifier", + "value": "box", + "range": [ + 78, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 6, + "column": 20 + }, + "end": { + "line": 6, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "width", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "*", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 6, + "column": 28 + } + } + }, + { + "type": "Identifier", + "value": "box", + "range": [ + 90, + 93 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 32 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 93, + 94 + ], + "loc": { + "start": { + "line": 6, + "column": 32 + }, + "end": { + "line": 6, + "column": 33 + } + } + }, + { + "type": "Identifier", + "value": "height", + "range": [ + 94, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 33 + }, + "end": { + "line": 6, + "column": 39 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 100, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 39 + }, + "end": { + "line": 6, + "column": 40 + } + } + }, + { + "type": "HTMLText", + "value": "\n ", + "range": [ + 101, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 40 + }, + "end": { + "line": 7, + "column": 2 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 104, + 105 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 3 + } + } + }, + { + "type": "Identifier", + "value": "box", + "range": [ + 105, + 108 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 108, + 109 + ], + "loc": { + "start": { + "line": 7, + "column": 6 + }, + "end": { + "line": 7, + "column": 7 + } + } + }, + { + "type": "Identifier", + "value": "width", + "range": [ + 109, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 114, + 115 + ], + "loc": { + "start": { + "line": 7, + "column": 12 + }, + "end": { + "line": 7, + "column": 13 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 115, + 116 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 14 + } + } + }, + { + "type": "HTMLText", + "value": "*", + "range": [ + 116, + 117 + ], + "loc": { + "start": { + "line": 7, + "column": 14 + }, + "end": { + "line": 7, + "column": 15 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 117, + 118 + ], + "loc": { + "start": { + "line": 7, + "column": 15 + }, + "end": { + "line": 7, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 118, + 119 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 17 + } + } + }, + { + "type": "Identifier", + "value": "box", + "range": [ + 119, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": ".", + "range": [ + 122, + 123 + ], + "loc": { + "start": { + "line": 7, + "column": 20 + }, + "end": { + "line": 7, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "height", + "range": [ + 123, + 129 + ], + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 7, + "column": 27 + }, + "end": { + "line": 7, + "column": 28 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 130, + 131 + ], + "loc": { + "start": { + "line": 7, + "column": 28 + }, + "end": { + "line": 7, + "column": 29 + } + } + }, + { + "type": "HTMLText", + "value": "=", + "range": [ + 131, + 132 + ], + "loc": { + "start": { + "line": 7, + "column": 29 + }, + "end": { + "line": 7, + "column": 30 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 7, + "column": 30 + }, + "end": { + "line": 7, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 7, + "column": 31 + }, + "end": { + "line": 7, + "column": 32 + } + } + }, + { + "type": "Identifier", + "value": "area", + "range": [ + 134, + 138 + ], + "loc": { + "start": { + "line": 7, + "column": 32 + }, + "end": { + "line": 7, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 138, + 139 + ], + "loc": { + "start": { + "line": 7, + "column": 36 + }, + "end": { + "line": 7, + "column": 37 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 1 + } + } + }, + { + "type": "MustacheKeyword", + "value": "/each", + "range": [ + 141, + 146 + ], + "loc": { + "start": { + "line": 8, + "column": 1 + }, + "end": { + "line": 8, + "column": 6 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 8, + "column": 6 + }, + "end": { + "line": 8, + "column": 7 + } + } + } + ], + "range": [ + 0, + 148 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/02-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/02-scope-output.json new file mode 100644 index 00000000..8ae111b3 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/10.1-at-const/02-scope-output.json @@ -0,0 +1,1463 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [ + { + "name": "boxes", + "identifiers": [ + { + "type": "Identifier", + "name": "boxes", + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "boxes", + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "boxes", + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "init": null, + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "boxes", + "range": [ + 47, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "boxes", + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "boxes", + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "boxes", + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "boxes", + "range": [ + 47, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "from": "module", + "init": null, + "resolved": { + "type": "Identifier", + "name": "boxes", + "range": [ + 22, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 18 + } + } + } + } + ], + "childScopes": [ + { + "type": "function", + "variables": [ + { + "name": "box", + "identifiers": [ + { + "type": "Identifier", + "name": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + } + ], + "defs": [ + { + "type": "Parameter", + "name": { + "type": "Identifier", + "name": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + "node": { + "type": "SvelteEachBlock", + "expression": { + "type": "Identifier", + "name": "boxes", + "range": [ + 47, + 52 + ], + "loc": { + "start": { + "line": 5, + "column": 7 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "context": { + "type": "Identifier", + "name": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + }, + "index": null, + "key": null, + "children": [ + { + "type": "SvelteConstTag", + "declaration": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "area", + "range": [ + 71, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "init": { + "type": "BinaryExpression", + "left": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "box", + "range": [ + 78, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "width", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + "range": [ + 78, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + "operator": "*", + "right": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "box", + "range": [ + 90, + 93 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 32 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "height", + "range": [ + 94, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 33 + }, + "end": { + "line": 6, + "column": 39 + } + } + }, + "range": [ + 90, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 39 + } + } + }, + "range": [ + 78, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 39 + } + } + }, + "range": [ + 71, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 39 + } + } + }, + "range": [ + 63, + 101 + ], + "loc": { + "start": { + "line": 6, + "column": 2 + }, + "end": { + "line": 6, + "column": 40 + } + } + }, + { + "type": "SvelteText", + "value": "\n ", + "range": [ + 101, + 104 + ], + "loc": { + "start": { + "line": 6, + "column": 40 + }, + "end": { + "line": 7, + "column": 2 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "box", + "range": [ + 105, + 108 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 6 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "width", + "range": [ + 109, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 7 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 105, + 114 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 12 + } + } + }, + "range": [ + 104, + 115 + ], + "loc": { + "start": { + "line": 7, + "column": 2 + }, + "end": { + "line": 7, + "column": 13 + } + } + }, + { + "type": "SvelteText", + "value": " * ", + "range": [ + 115, + 118 + ], + "loc": { + "start": { + "line": 7, + "column": 13 + }, + "end": { + "line": 7, + "column": 16 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "box", + "range": [ + 119, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "height", + "range": [ + 123, + 129 + ], + "loc": { + "start": { + "line": 7, + "column": 21 + }, + "end": { + "line": 7, + "column": 27 + } + } + }, + "range": [ + 119, + 129 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 27 + } + } + }, + "range": [ + 118, + 130 + ], + "loc": { + "start": { + "line": 7, + "column": 16 + }, + "end": { + "line": 7, + "column": 28 + } + } + }, + { + "type": "SvelteText", + "value": " = ", + "range": [ + 130, + 133 + ], + "loc": { + "start": { + "line": 7, + "column": 28 + }, + "end": { + "line": 7, + "column": 31 + } + } + }, + { + "type": "SvelteMustacheTag", + "kind": "text", + "expression": { + "type": "Identifier", + "name": "area", + "range": [ + 134, + 138 + ], + "loc": { + "start": { + "line": 7, + "column": 32 + }, + "end": { + "line": 7, + "column": 36 + } + } + }, + "range": [ + 133, + 139 + ], + "loc": { + "start": { + "line": 7, + "column": 31 + }, + "end": { + "line": 7, + "column": 37 + } + } + } + ], + "else": null, + "range": [ + 40, + 147 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 8, + "column": 7 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "box", + "range": [ + 78, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "box", + "range": [ + 90, + 93 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 32 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "box", + "range": [ + 105, + 108 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 6 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "box", + "range": [ + 119, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + } + } + ] + }, + { + "name": "area", + "identifiers": [ + { + "type": "Identifier", + "name": "area", + "range": [ + 71, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 14 + } + } + } + ], + "defs": [ + { + "type": "Variable", + "name": { + "type": "Identifier", + "name": "area", + "range": [ + 71, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "node": { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "area", + "range": [ + 71, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "init": { + "type": "BinaryExpression", + "left": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "box", + "range": [ + 78, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "width", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 21 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + "range": [ + 78, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + "operator": "*", + "right": { + "type": "MemberExpression", + "computed": false, + "object": { + "type": "Identifier", + "name": "box", + "range": [ + 90, + 93 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 32 + } + } + }, + "optional": false, + "property": { + "type": "Identifier", + "name": "height", + "range": [ + 94, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 33 + }, + "end": { + "line": 6, + "column": 39 + } + } + }, + "range": [ + 90, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 39 + } + } + }, + "range": [ + 78, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 39 + } + } + }, + "range": [ + 71, + 100 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 39 + } + } + } + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "area", + "range": [ + 71, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "from": "function", + "init": true, + "resolved": { + "type": "Identifier", + "name": "area", + "range": [ + 71, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "area", + "range": [ + 134, + 138 + ], + "loc": { + "start": { + "line": 7, + "column": 32 + }, + "end": { + "line": 7, + "column": 36 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "area", + "range": [ + 71, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 14 + } + } + } + } + ] + } + ], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "area", + "range": [ + 71, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 14 + } + } + }, + "from": "function", + "init": true, + "resolved": { + "type": "Identifier", + "name": "area", + "range": [ + 71, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 14 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "box", + "range": [ + 78, + 81 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 20 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "box", + "range": [ + 90, + 93 + ], + "loc": { + "start": { + "line": 6, + "column": 29 + }, + "end": { + "line": 6, + "column": 32 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "box", + "range": [ + 105, + 108 + ], + "loc": { + "start": { + "line": 7, + "column": 3 + }, + "end": { + "line": 7, + "column": 6 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "box", + "range": [ + 119, + 122 + ], + "loc": { + "start": { + "line": 7, + "column": 17 + }, + "end": { + "line": 7, + "column": 20 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "box", + "range": [ + 56, + 59 + ], + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 19 + } + } + } + }, + { + "identifier": { + "type": "Identifier", + "name": "area", + "range": [ + 134, + 138 + ], + "loc": { + "start": { + "line": 7, + "column": 32 + }, + "end": { + "line": 7, + "column": 36 + } + } + }, + "from": "function", + "init": null, + "resolved": { + "type": "Identifier", + "name": "area", + "range": [ + 71, + 75 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 14 + } + } + } + } + ], + "childScopes": [], + "through": [] + } + ], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/01-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/01-input.svelte new file mode 100644 index 00000000..9f262af8 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/01-input.svelte @@ -0,0 +1,3 @@ + + + diff --git a/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/01-no-undef-result.json b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/01-no-undef-result.json new file mode 100644 index 00000000..4a6c9dd1 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/01-no-undef-result.json @@ -0,0 +1,14 @@ +[ + { + "ruleId": "no-undef", + "code": "value", + "line": 1, + "column": 22 + }, + { + "ruleId": "no-undef", + "code": "property", + "line": 3, + "column": 12 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/01-output.json b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/01-output.json new file mode 100644 index 00000000..854ae54f --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/01-output.json @@ -0,0 +1,1007 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "dov", + "range": [ + 1, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "property", + "range": [ + 11, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + "modifiers": [], + "range": [ + 5, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + "expression": { + "type": "Identifier", + "name": "value", + "range": [ + 21, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + "range": [ + 5, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 27 + } + } + } + ], + "selfClosing": true, + "range": [ + 0, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 0, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 2, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "dov", + "range": [ + 32, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "property", + "range": [ + 42, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "modifiers": [], + "range": [ + 36, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "expression": { + "type": "SvelteLiteral", + "value": "value", + "range": [ + 52, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + "range": [ + 36, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 27 + } + } + } + ], + "selfClosing": true, + "range": [ + 31, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 31, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 3, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "dov", + "range": [ + 63, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "property", + "range": [ + 73, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "modifiers": [], + "range": [ + 67, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "expression": { + "type": "Identifier", + "name": "property", + "range": [ + 73, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "range": [ + 67, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 19 + } + } + } + ], + "selfClosing": true, + "range": [ + 62, + 84 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 22 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 62, + 84 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 22 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "dov", + "range": [ + 1, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 5, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "property", + "range": [ + 11, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + { + "type": "Identifier", + "value": "value", + "range": [ + 21, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 2, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "dov", + "range": [ + 32, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 36, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "property", + "range": [ + 42, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + { + "type": "HTMLText", + "value": "value", + "range": [ + 52, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 3, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "dov", + "range": [ + 63, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 67, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "property", + "range": [ + 73, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 82, + 83 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 83, + 84 + ], + "loc": { + "start": { + "line": 3, + "column": 21 + }, + "end": { + "line": 3, + "column": 22 + } + } + } + ], + "range": [ + 0, + 85 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/01-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/01-scope-output.json new file mode 100644 index 00000000..3fed4aeb --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/01-scope-output.json @@ -0,0 +1,175 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "value", + "range": [ + 21, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "property", + "range": [ + 73, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "value", + "range": [ + 21, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "property", + "range": [ + 73, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "value", + "range": [ + 21, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "property", + "range": [ + 73, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/02-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/02-input.svelte new file mode 100644 index 00000000..87a5e729 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/02-input.svelte @@ -0,0 +1,12 @@ + +
...
+
...
+ + +
...
+ + +
...
+ + +
...
diff --git a/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/02-no-undef-result.json b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/02-no-undef-result.json new file mode 100644 index 00000000..0081495a --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/02-no-undef-result.json @@ -0,0 +1,26 @@ +[ + { + "ruleId": "no-undef", + "code": "myColor", + "line": 6, + "column": 19 + }, + { + "ruleId": "no-undef", + "code": "color", + "line": 9, + "column": 12 + }, + { + "ruleId": "no-undef", + "code": "color", + "line": 12, + "column": 12 + }, + { + "ruleId": "no-undef", + "code": "darkMode", + "line": 12, + "column": 62 + } +] \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/02-output.json b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/02-output.json new file mode 100644 index 00000000..845d2bce --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/02-output.json @@ -0,0 +1,2993 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteHTMLComment", + "value": " These are equivalent ", + "range": [ + 0, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 2, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 31, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "color", + "range": [ + 41, + 46 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "modifiers": [], + "range": [ + 35, + 46 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + "expression": { + "type": "SvelteLiteral", + "value": "red", + "range": [ + 48, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + "range": [ + 35, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 22 + } + } + } + ], + "selfClosing": false, + "range": [ + 30, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "...", + "range": [ + 53, + 56 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 26 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 56, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + "range": [ + 30, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 3, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 64, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "style", + "range": [ + 68, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteLiteral", + "value": "color: red;", + "range": [ + 75, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 23 + } + } + } + ], + "range": [ + 68, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 24 + } + } + } + ], + "selfClosing": false, + "range": [ + 63, + 88 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "...", + "range": [ + 88, + 91 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 3, + "column": 28 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 91, + 97 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 34 + } + } + }, + "range": [ + 63, + 97 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 34 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 97, + 99 + ], + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "SvelteHTMLComment", + "value": " Variables can be used ", + "range": [ + 99, + 129 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 30 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 5, + "column": 30 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 131, + 134 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "color", + "range": [ + 141, + 146 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 16 + } + } + }, + "modifiers": [], + "range": [ + 135, + 146 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 16 + } + } + }, + "expression": { + "type": "Identifier", + "name": "myColor", + "range": [ + 148, + 155 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "range": [ + 135, + 156 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 26 + } + } + } + ], + "selfClosing": false, + "range": [ + 130, + 157 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 27 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "...", + "range": [ + 157, + 160 + ], + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 6, + "column": 30 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 160, + 166 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 6, + "column": 36 + } + } + }, + "range": [ + 130, + 166 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 36 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 166, + 168 + ], + "loc": { + "start": { + "line": 6, + "column": 36 + }, + "end": { + "line": 8, + "column": 0 + } + } + }, + { + "type": "SvelteHTMLComment", + "value": " Shorthand, for when property and variable name match ", + "range": [ + 168, + 229 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 61 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 229, + 230 + ], + "loc": { + "start": { + "line": 8, + "column": 61 + }, + "end": { + "line": 9, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 231, + 234 + ], + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "color", + "range": [ + 241, + 246 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + "modifiers": [], + "range": [ + 235, + 246 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + "expression": { + "type": "Identifier", + "name": "color", + "range": [ + 241, + 246 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + "range": [ + 235, + 246 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 16 + } + } + } + ], + "selfClosing": false, + "range": [ + 230, + 247 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 17 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "...", + "range": [ + 247, + 250 + ], + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 20 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 250, + 256 + ], + "loc": { + "start": { + "line": 9, + "column": 20 + }, + "end": { + "line": 9, + "column": 26 + } + } + }, + "range": [ + 230, + 256 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 26 + } + } + }, + { + "type": "SvelteText", + "value": "\n\n", + "range": [ + 256, + 258 + ], + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 11, + "column": 0 + } + } + }, + { + "type": "SvelteHTMLComment", + "value": " Multiple styles can be included ", + "range": [ + 258, + 298 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 40 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 298, + 299 + ], + "loc": { + "start": { + "line": 11, + "column": 40 + }, + "end": { + "line": 12, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 300, + 303 + ], + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "color", + "range": [ + 310, + 315 + ], + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + "modifiers": [], + "range": [ + 304, + 315 + ], + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + "expression": { + "type": "Identifier", + "name": "color", + "range": [ + 310, + 315 + ], + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + "range": [ + 304, + 315 + ], + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "width", + "range": [ + 322, + 327 + ], + "loc": { + "start": { + "line": 12, + "column": 23 + }, + "end": { + "line": 12, + "column": 28 + } + } + }, + "modifiers": [], + "range": [ + 316, + 327 + ], + "loc": { + "start": { + "line": 12, + "column": 17 + }, + "end": { + "line": 12, + "column": 28 + } + } + }, + "expression": { + "type": "SvelteLiteral", + "value": "12rem", + "range": [ + 329, + 334 + ], + "loc": { + "start": { + "line": 12, + "column": 30 + }, + "end": { + "line": 12, + "column": 35 + } + } + }, + "range": [ + 316, + 335 + ], + "loc": { + "start": { + "line": 12, + "column": 17 + }, + "end": { + "line": 12, + "column": 36 + } + } + }, + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "background-color", + "range": [ + 342, + 358 + ], + "loc": { + "start": { + "line": 12, + "column": 43 + }, + "end": { + "line": 12, + "column": 59 + } + } + }, + "modifiers": [], + "range": [ + 336, + 358 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 59 + } + } + }, + "expression": { + "type": "ConditionalExpression", + "alternate": { + "type": "Literal", + "raw": "\"white\"", + "value": "white", + "range": [ + 381, + 388 + ], + "loc": { + "start": { + "line": 12, + "column": 82 + }, + "end": { + "line": 12, + "column": 89 + } + } + }, + "consequent": { + "type": "Literal", + "raw": "\"black\"", + "value": "black", + "range": [ + 371, + 378 + ], + "loc": { + "start": { + "line": 12, + "column": 72 + }, + "end": { + "line": 12, + "column": 79 + } + } + }, + "test": { + "type": "Identifier", + "name": "darkMode", + "range": [ + 360, + 368 + ], + "loc": { + "start": { + "line": 12, + "column": 61 + }, + "end": { + "line": 12, + "column": 69 + } + } + }, + "range": [ + 360, + 388 + ], + "loc": { + "start": { + "line": 12, + "column": 61 + }, + "end": { + "line": 12, + "column": 89 + } + } + }, + "range": [ + 336, + 389 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 90 + } + } + } + ], + "selfClosing": false, + "range": [ + 299, + 390 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 91 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "...", + "range": [ + 390, + 393 + ], + "loc": { + "start": { + "line": 12, + "column": 91 + }, + "end": { + "line": 12, + "column": 94 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 393, + 399 + ], + "loc": { + "start": { + "line": 12, + "column": 94 + }, + "end": { + "line": 12, + "column": 100 + } + } + }, + "range": [ + 299, + 399 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 100 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "HTMLComment", + "value": "", + "range": [ + 0, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 2, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 31, + 34 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 35, + 40 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 40, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "color", + "range": [ + 41, + 46 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 46, + 47 + ], + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 47, + 48 + ], + "loc": { + "start": { + "line": 2, + "column": 17 + }, + "end": { + "line": 2, + "column": 18 + } + } + }, + { + "type": "HTMLText", + "value": "red", + "range": [ + 48, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 52, + 53 + ], + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + } + } + }, + { + "type": "HTMLText", + "value": "...", + "range": [ + 53, + 56 + ], + "loc": { + "start": { + "line": 2, + "column": 23 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 27 + }, + "end": { + "line": 2, + "column": 28 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 58, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 31 + }, + "end": { + "line": 2, + "column": 32 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 2, + "column": 32 + }, + "end": { + "line": 3, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 63, + 64 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 64, + 67 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 68, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 73, + 74 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 12 + } + } + }, + { + "type": "HTMLText", + "value": "color:", + "range": [ + 75, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 18 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + { + "type": "HTMLText", + "value": "red;", + "range": [ + 82, + 86 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 23 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 23 + }, + "end": { + "line": 3, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 3, + "column": 24 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "HTMLText", + "value": "...", + "range": [ + 88, + 91 + ], + "loc": { + "start": { + "line": 3, + "column": 25 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 92, + 93 + ], + "loc": { + "start": { + "line": 3, + "column": 29 + }, + "end": { + "line": 3, + "column": 30 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 93, + 96 + ], + "loc": { + "start": { + "line": 3, + "column": 30 + }, + "end": { + "line": 3, + "column": 33 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 96, + 97 + ], + "loc": { + "start": { + "line": 3, + "column": 33 + }, + "end": { + "line": 3, + "column": 34 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 97, + 99 + ], + "loc": { + "start": { + "line": 3, + "column": 34 + }, + "end": { + "line": 5, + "column": 0 + } + } + }, + { + "type": "HTMLComment", + "value": "", + "range": [ + 99, + 129 + ], + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 30 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 129, + 130 + ], + "loc": { + "start": { + "line": 5, + "column": 30 + }, + "end": { + "line": 6, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 130, + 131 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 131, + 134 + ], + "loc": { + "start": { + "line": 6, + "column": 1 + }, + "end": { + "line": 6, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 135, + 140 + ], + "loc": { + "start": { + "line": 6, + "column": 5 + }, + "end": { + "line": 6, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 140, + 141 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "color", + "range": [ + 141, + 146 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 6, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 146, + 147 + ], + "loc": { + "start": { + "line": 6, + "column": 16 + }, + "end": { + "line": 6, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 147, + 148 + ], + "loc": { + "start": { + "line": 6, + "column": 17 + }, + "end": { + "line": 6, + "column": 18 + } + } + }, + { + "type": "Identifier", + "value": "myColor", + "range": [ + 148, + 155 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 155, + 156 + ], + "loc": { + "start": { + "line": 6, + "column": 25 + }, + "end": { + "line": 6, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 156, + 157 + ], + "loc": { + "start": { + "line": 6, + "column": 26 + }, + "end": { + "line": 6, + "column": 27 + } + } + }, + { + "type": "HTMLText", + "value": "...", + "range": [ + 157, + 160 + ], + "loc": { + "start": { + "line": 6, + "column": 27 + }, + "end": { + "line": 6, + "column": 30 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 160, + 161 + ], + "loc": { + "start": { + "line": 6, + "column": 30 + }, + "end": { + "line": 6, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 161, + 162 + ], + "loc": { + "start": { + "line": 6, + "column": 31 + }, + "end": { + "line": 6, + "column": 32 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 162, + 165 + ], + "loc": { + "start": { + "line": 6, + "column": 32 + }, + "end": { + "line": 6, + "column": 35 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 165, + 166 + ], + "loc": { + "start": { + "line": 6, + "column": 35 + }, + "end": { + "line": 6, + "column": 36 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 166, + 168 + ], + "loc": { + "start": { + "line": 6, + "column": 36 + }, + "end": { + "line": 8, + "column": 0 + } + } + }, + { + "type": "HTMLComment", + "value": "", + "range": [ + 168, + 229 + ], + "loc": { + "start": { + "line": 8, + "column": 0 + }, + "end": { + "line": 8, + "column": 61 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 229, + 230 + ], + "loc": { + "start": { + "line": 8, + "column": 61 + }, + "end": { + "line": 9, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 230, + 231 + ], + "loc": { + "start": { + "line": 9, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 231, + 234 + ], + "loc": { + "start": { + "line": 9, + "column": 1 + }, + "end": { + "line": 9, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 235, + 240 + ], + "loc": { + "start": { + "line": 9, + "column": 5 + }, + "end": { + "line": 9, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 240, + 241 + ], + "loc": { + "start": { + "line": 9, + "column": 10 + }, + "end": { + "line": 9, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "color", + "range": [ + 241, + 246 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 246, + 247 + ], + "loc": { + "start": { + "line": 9, + "column": 16 + }, + "end": { + "line": 9, + "column": 17 + } + } + }, + { + "type": "HTMLText", + "value": "...", + "range": [ + 247, + 250 + ], + "loc": { + "start": { + "line": 9, + "column": 17 + }, + "end": { + "line": 9, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 250, + 251 + ], + "loc": { + "start": { + "line": 9, + "column": 20 + }, + "end": { + "line": 9, + "column": 21 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 251, + 252 + ], + "loc": { + "start": { + "line": 9, + "column": 21 + }, + "end": { + "line": 9, + "column": 22 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 252, + 255 + ], + "loc": { + "start": { + "line": 9, + "column": 22 + }, + "end": { + "line": 9, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 255, + 256 + ], + "loc": { + "start": { + "line": 9, + "column": 25 + }, + "end": { + "line": 9, + "column": 26 + } + } + }, + { + "type": "HTMLText", + "value": "\n\n", + "range": [ + 256, + 258 + ], + "loc": { + "start": { + "line": 9, + "column": 26 + }, + "end": { + "line": 11, + "column": 0 + } + } + }, + { + "type": "HTMLComment", + "value": "", + "range": [ + 258, + 298 + ], + "loc": { + "start": { + "line": 11, + "column": 0 + }, + "end": { + "line": 11, + "column": 40 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 298, + 299 + ], + "loc": { + "start": { + "line": 11, + "column": 40 + }, + "end": { + "line": 12, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 299, + 300 + ], + "loc": { + "start": { + "line": 12, + "column": 0 + }, + "end": { + "line": 12, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 300, + 303 + ], + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 12, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 304, + 309 + ], + "loc": { + "start": { + "line": 12, + "column": 5 + }, + "end": { + "line": 12, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 309, + 310 + ], + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 11 + } + } + }, + { + "type": "Identifier", + "value": "color", + "range": [ + 310, + 315 + ], + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 316, + 321 + ], + "loc": { + "start": { + "line": 12, + "column": 17 + }, + "end": { + "line": 12, + "column": 22 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 321, + 322 + ], + "loc": { + "start": { + "line": 12, + "column": 22 + }, + "end": { + "line": 12, + "column": 23 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "width", + "range": [ + 322, + 327 + ], + "loc": { + "start": { + "line": 12, + "column": 23 + }, + "end": { + "line": 12, + "column": 28 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 327, + 328 + ], + "loc": { + "start": { + "line": 12, + "column": 28 + }, + "end": { + "line": 12, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 328, + 329 + ], + "loc": { + "start": { + "line": 12, + "column": 29 + }, + "end": { + "line": 12, + "column": 30 + } + } + }, + { + "type": "HTMLText", + "value": "12rem", + "range": [ + 329, + 334 + ], + "loc": { + "start": { + "line": 12, + "column": 30 + }, + "end": { + "line": 12, + "column": 35 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 334, + 335 + ], + "loc": { + "start": { + "line": 12, + "column": 35 + }, + "end": { + "line": 12, + "column": 36 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 336, + 341 + ], + "loc": { + "start": { + "line": 12, + "column": 37 + }, + "end": { + "line": 12, + "column": 42 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 341, + 342 + ], + "loc": { + "start": { + "line": 12, + "column": 42 + }, + "end": { + "line": 12, + "column": 43 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "background-color", + "range": [ + 342, + 358 + ], + "loc": { + "start": { + "line": 12, + "column": 43 + }, + "end": { + "line": 12, + "column": 59 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 358, + 359 + ], + "loc": { + "start": { + "line": 12, + "column": 59 + }, + "end": { + "line": 12, + "column": 60 + } + } + }, + { + "type": "Punctuator", + "value": "{", + "range": [ + 359, + 360 + ], + "loc": { + "start": { + "line": 12, + "column": 60 + }, + "end": { + "line": 12, + "column": 61 + } + } + }, + { + "type": "Identifier", + "value": "darkMode", + "range": [ + 360, + 368 + ], + "loc": { + "start": { + "line": 12, + "column": 61 + }, + "end": { + "line": 12, + "column": 69 + } + } + }, + { + "type": "Punctuator", + "value": "?", + "range": [ + 369, + 370 + ], + "loc": { + "start": { + "line": 12, + "column": 70 + }, + "end": { + "line": 12, + "column": 71 + } + } + }, + { + "type": "String", + "value": "\"black\"", + "range": [ + 371, + 378 + ], + "loc": { + "start": { + "line": 12, + "column": 72 + }, + "end": { + "line": 12, + "column": 79 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 379, + 380 + ], + "loc": { + "start": { + "line": 12, + "column": 80 + }, + "end": { + "line": 12, + "column": 81 + } + } + }, + { + "type": "String", + "value": "\"white\"", + "range": [ + 381, + 388 + ], + "loc": { + "start": { + "line": 12, + "column": 82 + }, + "end": { + "line": 12, + "column": 89 + } + } + }, + { + "type": "Punctuator", + "value": "}", + "range": [ + 388, + 389 + ], + "loc": { + "start": { + "line": 12, + "column": 89 + }, + "end": { + "line": 12, + "column": 90 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 389, + 390 + ], + "loc": { + "start": { + "line": 12, + "column": 90 + }, + "end": { + "line": 12, + "column": 91 + } + } + }, + { + "type": "HTMLText", + "value": "...", + "range": [ + 390, + 393 + ], + "loc": { + "start": { + "line": 12, + "column": 91 + }, + "end": { + "line": 12, + "column": 94 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 393, + 394 + ], + "loc": { + "start": { + "line": 12, + "column": 94 + }, + "end": { + "line": 12, + "column": 95 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 394, + 395 + ], + "loc": { + "start": { + "line": 12, + "column": 95 + }, + "end": { + "line": 12, + "column": 96 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 395, + 398 + ], + "loc": { + "start": { + "line": 12, + "column": 96 + }, + "end": { + "line": 12, + "column": 99 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 398, + 399 + ], + "loc": { + "start": { + "line": 12, + "column": 99 + }, + "end": { + "line": 12, + "column": 100 + } + } + } + ], + "range": [ + 0, + 400 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 13, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/02-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/02-scope-output.json new file mode 100644 index 00000000..56146b73 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/02-scope-output.json @@ -0,0 +1,313 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [], + "references": [ + { + "identifier": { + "type": "Identifier", + "name": "myColor", + "range": [ + 148, + 155 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "color", + "range": [ + 241, + 246 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "color", + "range": [ + 310, + 315 + ], + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "darkMode", + "range": [ + 360, + 368 + ], + "loc": { + "start": { + "line": 12, + "column": 61 + }, + "end": { + "line": 12, + "column": 69 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ], + "childScopes": [], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "myColor", + "range": [ + 148, + 155 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "color", + "range": [ + 241, + 246 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "color", + "range": [ + 310, + 315 + ], + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "darkMode", + "range": [ + 360, + 368 + ], + "loc": { + "start": { + "line": 12, + "column": 61 + }, + "end": { + "line": 12, + "column": 69 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] + } + ], + "through": [ + { + "identifier": { + "type": "Identifier", + "name": "myColor", + "range": [ + 148, + 155 + ], + "loc": { + "start": { + "line": 6, + "column": 18 + }, + "end": { + "line": 6, + "column": 25 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "color", + "range": [ + 241, + 246 + ], + "loc": { + "start": { + "line": 9, + "column": 11 + }, + "end": { + "line": 9, + "column": 16 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "color", + "range": [ + 310, + 315 + ], + "loc": { + "start": { + "line": 12, + "column": 11 + }, + "end": { + "line": 12, + "column": 16 + } + } + }, + "from": "module", + "init": null, + "resolved": null + }, + { + "identifier": { + "type": "Identifier", + "name": "darkMode", + "range": [ + 360, + 368 + ], + "loc": { + "start": { + "line": 12, + "column": 61 + }, + "end": { + "line": 12, + "column": 69 + } + } + }, + "from": "module", + "init": null, + "resolved": null + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/03-input.svelte b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/03-input.svelte new file mode 100644 index 00000000..3ba4b677 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/03-input.svelte @@ -0,0 +1 @@ +
This will be red
diff --git a/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/03-output.json b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/03-output.json new file mode 100644 index 00000000..33a043c2 --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/03-output.json @@ -0,0 +1,748 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 1, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteAttribute", + "key": { + "type": "SvelteName", + "name": "style", + "range": [ + 5, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + "boolean": false, + "value": [ + { + "type": "SvelteLiteral", + "value": "color: blue;", + "range": [ + 12, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 24 + } + } + } + ], + "range": [ + 5, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 25 + } + } + }, + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "color", + "range": [ + 32, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 37 + } + } + }, + "modifiers": [], + "range": [ + 26, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 37 + } + } + }, + "expression": { + "type": "SvelteLiteral", + "value": "red", + "range": [ + 39, + 42 + ], + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 42 + } + } + }, + "range": [ + 26, + 43 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 43 + } + } + } + ], + "selfClosing": false, + "range": [ + 0, + 44 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 44 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "This will be red", + "range": [ + 44, + 60 + ], + "loc": { + "start": { + "line": 1, + "column": 44 + }, + "end": { + "line": 1, + "column": 60 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 60, + 66 + ], + "loc": { + "start": { + "line": 1, + "column": 60 + }, + "end": { + "line": 1, + "column": 66 + } + } + }, + "range": [ + 0, + 66 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 66 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 1, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 5, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 11, + 12 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + } + } + }, + { + "type": "HTMLText", + "value": "color:", + "range": [ + 12, + 18 + ], + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 18 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 18, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + { + "type": "HTMLText", + "value": "blue;", + "range": [ + 19, + 24 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 24 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 24, + 25 + ], + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 25 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 26, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 31 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "color", + "range": [ + 32, + 37 + ], + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 37 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 37, + 38 + ], + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 38 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 38, + 39 + ], + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 39 + } + } + }, + { + "type": "HTMLText", + "value": "red", + "range": [ + 39, + 42 + ], + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 42 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 42, + 43 + ], + "loc": { + "start": { + "line": 1, + "column": 42 + }, + "end": { + "line": 1, + "column": 43 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 43, + 44 + ], + "loc": { + "start": { + "line": 1, + "column": 43 + }, + "end": { + "line": 1, + "column": 44 + } + } + }, + { + "type": "HTMLText", + "value": "This", + "range": [ + 44, + 48 + ], + "loc": { + "start": { + "line": 1, + "column": 44 + }, + "end": { + "line": 1, + "column": 48 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 48, + 49 + ], + "loc": { + "start": { + "line": 1, + "column": 48 + }, + "end": { + "line": 1, + "column": 49 + } + } + }, + { + "type": "HTMLText", + "value": "will", + "range": [ + 49, + 53 + ], + "loc": { + "start": { + "line": 1, + "column": 49 + }, + "end": { + "line": 1, + "column": 53 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 53, + 54 + ], + "loc": { + "start": { + "line": 1, + "column": 53 + }, + "end": { + "line": 1, + "column": 54 + } + } + }, + { + "type": "HTMLText", + "value": "be", + "range": [ + 54, + 56 + ], + "loc": { + "start": { + "line": 1, + "column": 54 + }, + "end": { + "line": 1, + "column": 56 + } + } + }, + { + "type": "HTMLText", + "value": " ", + "range": [ + 56, + 57 + ], + "loc": { + "start": { + "line": 1, + "column": 56 + }, + "end": { + "line": 1, + "column": 57 + } + } + }, + { + "type": "HTMLText", + "value": "red", + "range": [ + 57, + 60 + ], + "loc": { + "start": { + "line": 1, + "column": 57 + }, + "end": { + "line": 1, + "column": 60 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 1, + "column": 60 + }, + "end": { + "line": 1, + "column": 61 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 1, + "column": 61 + }, + "end": { + "line": 1, + "column": 62 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 62, + 65 + ], + "loc": { + "start": { + "line": 1, + "column": 62 + }, + "end": { + "line": 1, + "column": 65 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 65, + 66 + ], + "loc": { + "start": { + "line": 1, + "column": 65 + }, + "end": { + "line": 1, + "column": 66 + } + } + } + ], + "range": [ + 0, + 67 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/03-scope-output.json b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/03-scope-output.json new file mode 100644 index 00000000..d392ca4b --- /dev/null +++ b/tests/fixtures/parser/ast/docs/template-syntax/11-element-directives/05.1-style-property/03-scope-output.json @@ -0,0 +1,34 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [], + "references": [], + "childScopes": [], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/style-directive01-input.svelte b/tests/fixtures/parser/ast/style-directive01-input.svelte new file mode 100644 index 00000000..9ab829e2 --- /dev/null +++ b/tests/fixtures/parser/ast/style-directive01-input.svelte @@ -0,0 +1,4 @@ +
+
+
+
...
diff --git a/tests/fixtures/parser/ast/style-directive01-output.json b/tests/fixtures/parser/ast/style-directive01-output.json new file mode 100644 index 00000000..37042437 --- /dev/null +++ b/tests/fixtures/parser/ast/style-directive01-output.json @@ -0,0 +1,1514 @@ +{ + "type": "Program", + "body": [ + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 1, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "property", + "range": [ + 11, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + "modifiers": [], + "range": [ + 5, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + "expression": { + "type": "SvelteLiteral", + "value": "value", + "range": [ + 21, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + "range": [ + 5, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 27 + } + } + } + ], + "selfClosing": true, + "range": [ + 0, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 0, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 2, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 32, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "property", + "range": [ + 42, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "modifiers": [], + "range": [ + 36, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + "expression": { + "type": "SvelteLiteral", + "value": "value", + "range": [ + 52, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + "range": [ + 36, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 27 + } + } + } + ], + "selfClosing": true, + "range": [ + 31, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 31, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 3, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 63, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "property", + "range": [ + 73, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "modifiers": [], + "range": [ + 67, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + "expression": { + "type": "SvelteLiteral", + "value": "value", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + "range": [ + 67, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 25 + } + } + } + ], + "selfClosing": true, + "range": [ + 62, + 90 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + "children": [], + "endTag": null, + "range": [ + 62, + 90 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + { + "type": "SvelteText", + "value": "\n", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 4, + "column": 0 + } + } + }, + { + "type": "SvelteElement", + "kind": "html", + "name": { + "type": "SvelteName", + "name": "div", + "range": [ + 92, + 95 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 4 + } + } + }, + "startTag": { + "type": "SvelteStartTag", + "attributes": [ + { + "type": "SvelteDirective", + "kind": "Style", + "key": { + "type": "SvelteDirectiveKey", + "name": { + "type": "SvelteName", + "name": "color", + "range": [ + 102, + 107 + ], + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + "modifiers": [], + "range": [ + 96, + 107 + ], + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + "expression": { + "type": "SvelteLiteral", + "value": "red", + "range": [ + 109, + 127 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 36 + } + } + }, + "range": [ + 96, + 128 + ], + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 37 + } + } + } + ], + "selfClosing": false, + "range": [ + 91, + 129 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 38 + } + } + }, + "children": [ + { + "type": "SvelteText", + "value": "...", + "range": [ + 129, + 132 + ], + "loc": { + "start": { + "line": 4, + "column": 38 + }, + "end": { + "line": 4, + "column": 41 + } + } + } + ], + "endTag": { + "type": "SvelteEndTag", + "range": [ + 132, + 138 + ], + "loc": { + "start": { + "line": 4, + "column": 41 + }, + "end": { + "line": 4, + "column": 47 + } + } + }, + "range": [ + 91, + 138 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 47 + } + } + } + ], + "sourceType": "module", + "comments": [], + "tokens": [ + { + "type": "Punctuator", + "value": "<", + "range": [ + 0, + 1 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 1, + 4 + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 5, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 10, + 11 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "property", + "range": [ + 11, + 19 + ], + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 19, + 20 + ], + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 20, + 21 + ], + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + } + }, + { + "type": "HTMLText", + "value": "value", + "range": [ + 21, + 26 + ], + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 28, + 29 + ], + "loc": { + "start": { + "line": 1, + "column": 28 + }, + "end": { + "line": 1, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 29, + 30 + ], + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 30, + 31 + ], + "loc": { + "start": { + "line": 1, + "column": 30 + }, + "end": { + "line": 2, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 31, + 32 + ], + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 32, + 35 + ], + "loc": { + "start": { + "line": 2, + "column": 1 + }, + "end": { + "line": 2, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 36, + 41 + ], + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 41, + 42 + ], + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "property", + "range": [ + 42, + 50 + ], + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 50, + 51 + ], + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "value": "'", + "range": [ + 51, + 52 + ], + "loc": { + "start": { + "line": 2, + "column": 20 + }, + "end": { + "line": 2, + "column": 21 + } + } + }, + { + "type": "HTMLText", + "value": "value", + "range": [ + 52, + 57 + ], + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 26 + } + } + }, + { + "type": "Punctuator", + "value": "'", + "range": [ + 57, + 58 + ], + "loc": { + "start": { + "line": 2, + "column": 26 + }, + "end": { + "line": 2, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 59, + 60 + ], + "loc": { + "start": { + "line": 2, + "column": 28 + }, + "end": { + "line": 2, + "column": 29 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 60, + 61 + ], + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 30 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 61, + 62 + ], + "loc": { + "start": { + "line": 2, + "column": 30 + }, + "end": { + "line": 3, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 62, + 63 + ], + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 63, + 66 + ], + "loc": { + "start": { + "line": 3, + "column": 1 + }, + "end": { + "line": 3, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 67, + 72 + ], + "loc": { + "start": { + "line": 3, + "column": 5 + }, + "end": { + "line": 3, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 72, + 73 + ], + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "property", + "range": [ + 73, + 81 + ], + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 19 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 81, + 82 + ], + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 20 + } + } + }, + { + "type": "HTMLText", + "value": "value", + "range": [ + 82, + 87 + ], + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 25 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 88, + 89 + ], + "loc": { + "start": { + "line": 3, + "column": 26 + }, + "end": { + "line": 3, + "column": 27 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 89, + 90 + ], + "loc": { + "start": { + "line": 3, + "column": 27 + }, + "end": { + "line": 3, + "column": 28 + } + } + }, + { + "type": "HTMLText", + "value": "\n", + "range": [ + 90, + 91 + ], + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 4, + "column": 0 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 91, + 92 + ], + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 92, + 95 + ], + "loc": { + "start": { + "line": 4, + "column": 1 + }, + "end": { + "line": 4, + "column": 4 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "style", + "range": [ + 96, + 101 + ], + "loc": { + "start": { + "line": 4, + "column": 5 + }, + "end": { + "line": 4, + "column": 10 + } + } + }, + { + "type": "Punctuator", + "value": ":", + "range": [ + 101, + 102 + ], + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 11 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "color", + "range": [ + 102, + 107 + ], + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 16 + } + } + }, + { + "type": "Punctuator", + "value": "=", + "range": [ + 107, + 108 + ], + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 108, + 109 + ], + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + } + } + }, + { + "type": "HTMLText", + "value": "red", + "range": [ + 109, + 127 + ], + "loc": { + "start": { + "line": 4, + "column": 18 + }, + "end": { + "line": 4, + "column": 36 + } + } + }, + { + "type": "Punctuator", + "value": "\"", + "range": [ + 127, + 128 + ], + "loc": { + "start": { + "line": 4, + "column": 36 + }, + "end": { + "line": 4, + "column": 37 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 128, + 129 + ], + "loc": { + "start": { + "line": 4, + "column": 37 + }, + "end": { + "line": 4, + "column": 38 + } + } + }, + { + "type": "HTMLText", + "value": "...", + "range": [ + 129, + 132 + ], + "loc": { + "start": { + "line": 4, + "column": 38 + }, + "end": { + "line": 4, + "column": 41 + } + } + }, + { + "type": "Punctuator", + "value": "<", + "range": [ + 132, + 133 + ], + "loc": { + "start": { + "line": 4, + "column": 41 + }, + "end": { + "line": 4, + "column": 42 + } + } + }, + { + "type": "Punctuator", + "value": "/", + "range": [ + 133, + 134 + ], + "loc": { + "start": { + "line": 4, + "column": 42 + }, + "end": { + "line": 4, + "column": 43 + } + } + }, + { + "type": "HTMLIdentifier", + "value": "div", + "range": [ + 134, + 137 + ], + "loc": { + "start": { + "line": 4, + "column": 43 + }, + "end": { + "line": 4, + "column": 46 + } + } + }, + { + "type": "Punctuator", + "value": ">", + "range": [ + 137, + 138 + ], + "loc": { + "start": { + "line": 4, + "column": 46 + }, + "end": { + "line": 4, + "column": 47 + } + } + } + ], + "range": [ + 0, + 139 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 0 + } + } +} \ No newline at end of file diff --git a/tests/fixtures/parser/ast/style-directive01-scope-output.json b/tests/fixtures/parser/ast/style-directive01-scope-output.json new file mode 100644 index 00000000..d392ca4b --- /dev/null +++ b/tests/fixtures/parser/ast/style-directive01-scope-output.json @@ -0,0 +1,34 @@ +{ + "type": "global", + "variables": [ + { + "name": "$$slots", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$props", + "identifiers": [], + "defs": [], + "references": [] + }, + { + "name": "$$restProps", + "identifiers": [], + "defs": [], + "references": [] + } + ], + "references": [], + "childScopes": [ + { + "type": "module", + "variables": [], + "references": [], + "childScopes": [], + "through": [] + } + ], + "through": [] +} \ No newline at end of file diff --git a/tests/src/parser/test-utils.ts b/tests/src/parser/test-utils.ts index 900cd3d1..6348976a 100644 --- a/tests/src/parser/test-utils.ts +++ b/tests/src/parser/test-utils.ts @@ -204,6 +204,7 @@ const nodeToKeys: SvelteKeysType = { SvelteAwaitPendingBlock: ["children"], SvelteAwaitThenBlock: ["awaitThen", "value", "children"], SvelteDebugTag: ["identifiers"], + SvelteConstTag: ["declaration"], SvelteDirective: ["key", "intro", "outro", "expression"], SvelteDirectiveKey: ["name", "modifiers"], SvelteEachBlock: [