diff --git a/.changeset/gentle-views-matter.md b/.changeset/gentle-views-matter.md new file mode 100644 index 000000000000..2b0b361317ac --- /dev/null +++ b/.changeset/gentle-views-matter.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: preserve node locations for better sourcemaps diff --git a/packages/svelte/src/compiler/phases/1-parse/index.js b/packages/svelte/src/compiler/phases/1-parse/index.js index 8f7ef76be567..7017d013da32 100644 --- a/packages/svelte/src/compiler/phases/1-parse/index.js +++ b/packages/svelte/src/compiler/phases/1-parse/index.js @@ -1,4 +1,6 @@ /** @import { AST } from '#compiler' */ +/** @import { Location } from 'locate-character' */ +/** @import * as ESTree from 'estree' */ // @ts-expect-error acorn type definitions are borked in the release we use import { isIdentifierStart, isIdentifierChar } from 'acorn'; import fragment from './state/fragment.js'; @@ -218,31 +220,45 @@ export class Parser { return result; } - /** @param {any} allow_reserved */ - read_identifier(allow_reserved = false) { + /** + * @returns {ESTree.Identifier & { start: number, end: number, loc: { start: Location, end: Location } }} + */ + read_identifier() { const start = this.index; + let end = start; + let name = ''; - let i = this.index; + const code = /** @type {number} */ (this.template.codePointAt(this.index)); - const code = /** @type {number} */ (this.template.codePointAt(i)); - if (!isIdentifierStart(code, true)) return null; + if (isIdentifierStart(code, true)) { + let i = this.index; + end += code <= 0xffff ? 1 : 2; - i += code <= 0xffff ? 1 : 2; + while (end < this.template.length) { + const code = /** @type {number} */ (this.template.codePointAt(end)); - while (i < this.template.length) { - const code = /** @type {number} */ (this.template.codePointAt(i)); - - if (!isIdentifierChar(code, true)) break; - i += code <= 0xffff ? 1 : 2; - } + if (!isIdentifierChar(code, true)) break; + end += code <= 0xffff ? 1 : 2; + } - const identifier = this.template.slice(this.index, (this.index = i)); + name = this.template.slice(start, end); + this.index = end; - if (!allow_reserved && is_reserved(identifier)) { - e.unexpected_reserved_word(start, identifier); + if (is_reserved(name)) { + e.unexpected_reserved_word(start, name); + } } - return identifier; + return { + type: 'Identifier', + name, + start, + end, + loc: { + start: state.locator(start), + end: state.locator(end) + } + }; } /** @param {RegExp} pattern */ diff --git a/packages/svelte/src/compiler/phases/1-parse/read/context.js b/packages/svelte/src/compiler/phases/1-parse/read/context.js index 282288e2a22f..f90d59fa0bce 100644 --- a/packages/svelte/src/compiler/phases/1-parse/read/context.js +++ b/packages/svelte/src/compiler/phases/1-parse/read/context.js @@ -1,11 +1,9 @@ -/** @import { Location } from 'locate-character' */ /** @import { Pattern } from 'estree' */ /** @import { Parser } from '../index.js' */ import { match_bracket } from '../utils/bracket.js'; import { parse_expression_at } from '../acorn.js'; import { regex_not_newline_characters } from '../../patterns.js'; import * as e from '../../../errors.js'; -import { locator } from '../../../state.js'; /** * @param {Parser} parser @@ -15,20 +13,13 @@ export default function read_pattern(parser) { const start = parser.index; let i = parser.index; - const name = parser.read_identifier(); + const id = parser.read_identifier(); - if (name !== null) { + if (id.name !== '') { const annotation = read_type_annotation(parser); return { - type: 'Identifier', - name, - start, - loc: { - start: /** @type {Location} */ (locator(start)), - end: /** @type {Location} */ (locator(parser.index)) - }, - end: parser.index, + ...id, typeAnnotation: annotation }; } diff --git a/packages/svelte/src/compiler/phases/1-parse/state/element.js b/packages/svelte/src/compiler/phases/1-parse/state/element.js index bd1bd33c418f..d9fe33bbacf8 100644 --- a/packages/svelte/src/compiler/phases/1-parse/state/element.js +++ b/packages/svelte/src/compiler/phases/1-parse/state/element.js @@ -1,4 +1,5 @@ -/** @import { Expression } from 'estree' */ +/** @import { Expression, Identifier, SourceLocation } from 'estree' */ +/** @import { Location } from 'locate-character' */ /** @import { AST } from '#compiler' */ /** @import { Parser } from '../index.js' */ import { is_void } from '../../../../utils.js'; @@ -13,6 +14,8 @@ import { create_attribute, ExpressionMetadata, is_element_node } from '../../nod import { get_attribute_expression, is_expression_attribute } from '../../../utils/ast.js'; import { closing_tag_omitted } from '../../../../html-tree-validation.js'; import { list } from '../../../utils/string.js'; +import { locator } from '../../../state.js'; +import * as b from '#compiler/builders'; const regex_invalid_unquoted_attribute_value = /^(\/>|[\s"'=<>`])/; const regex_closing_textarea_tag = /^<\/textarea(\s[^>]*)?>/i; @@ -67,10 +70,9 @@ export default function element(parser) { return; } - const is_closing_tag = parser.eat('/'); - const name = parser.read_until(regex_whitespace_or_slash_or_closing_tag); + if (parser.eat('/')) { + const name = parser.read_until(regex_whitespace_or_slash_or_closing_tag); - if (is_closing_tag) { parser.allow_whitespace(); parser.eat('>', true); @@ -125,39 +127,41 @@ export default function element(parser) { return; } - if (name.startsWith('svelte:') && !meta_tags.has(name)) { - const bounds = { start: start + 1, end: start + 1 + name.length }; + const tag = read_tag(parser, regex_whitespace_or_slash_or_closing_tag); + + if (tag.name.startsWith('svelte:') && !meta_tags.has(tag.name)) { + const bounds = { start: start + 1, end: start + 1 + tag.name.length }; e.svelte_meta_invalid_tag(bounds, list(Array.from(meta_tags.keys()))); } - if (!regex_valid_element_name.test(name) && !regex_valid_component_name.test(name)) { + if (!regex_valid_element_name.test(tag.name) && !regex_valid_component_name.test(tag.name)) { // in the middle of typing -> allow in loose mode - if (!parser.loose || !name.endsWith('.')) { - const bounds = { start: start + 1, end: start + 1 + name.length }; + if (!parser.loose || !tag.name.endsWith('.')) { + const bounds = { start: start + 1, end: start + 1 + tag.name.length }; e.tag_invalid_name(bounds); } } - if (root_only_meta_tags.has(name)) { - if (name in parser.meta_tags) { - e.svelte_meta_duplicate(start, name); + if (root_only_meta_tags.has(tag.name)) { + if (tag.name in parser.meta_tags) { + e.svelte_meta_duplicate(start, tag.name); } if (parent.type !== 'Root') { - e.svelte_meta_invalid_placement(start, name); + e.svelte_meta_invalid_placement(start, tag.name); } - parser.meta_tags[name] = true; + parser.meta_tags[tag.name] = true; } - const type = meta_tags.has(name) - ? meta_tags.get(name) - : regex_valid_component_name.test(name) || (parser.loose && name.endsWith('.')) + const type = meta_tags.has(tag.name) + ? meta_tags.get(tag.name) + : regex_valid_component_name.test(tag.name) || (parser.loose && tag.name.endsWith('.')) ? 'Component' - : name === 'title' && parent_is_head(parser.stack) + : tag.name === 'title' && parent_is_head(parser.stack) ? 'TitleElement' : // TODO Svelte 6/7: once slots are removed in favor of snippets, always keep slot as a regular element - name === 'slot' && !parent_is_shadowroot_template(parser.stack) + tag.name === 'slot' && !parent_is_shadowroot_template(parser.stack) ? 'SlotElement' : 'RegularElement'; @@ -168,7 +172,8 @@ export default function element(parser) { type, start, end: -1, - name, + name: tag.name, + name_loc: tag.loc, attributes: [], fragment: create_fragment(true), metadata: { @@ -184,7 +189,8 @@ export default function element(parser) { type, start, end: -1, - name, + name: tag.name, + name_loc: tag.loc, attributes: [], fragment: create_fragment(true), metadata: { @@ -194,14 +200,14 @@ export default function element(parser) { parser.allow_whitespace(); - if (parent.type === 'RegularElement' && closing_tag_omitted(parent.name, name)) { + if (parent.type === 'RegularElement' && closing_tag_omitted(parent.name, tag.name)) { const end = parent.fragment.nodes[0]?.start ?? start; - w.element_implicitly_closed({ start: parent.start, end }, `<${name}>`, ``); + w.element_implicitly_closed({ start: parent.start, end }, `<${tag.name}>`, ``); parent.end = start; parser.pop(); parser.last_auto_closed_tag = { tag: parent.name, - reason: name, + reason: tag.name, depth: parser.stack.length }; } @@ -211,7 +217,7 @@ export default function element(parser) { const current = parser.current(); const is_top_level_script_or_style = - (name === 'script' || name === 'style') && current.type === 'Root'; + (tag.name === 'script' || tag.name === 'style') && current.type === 'Root'; const read = is_top_level_script_or_style ? read_static_attribute : read_attribute; @@ -324,7 +330,7 @@ export default function element(parser) { } } - if (name === 'script') { + if (tag.name === 'script') { const content = read_script(parser, start, element.attributes); if (prev_comment) { // We take advantage of the fact that the root will never have leadingComments set, @@ -352,7 +358,7 @@ export default function element(parser) { parser.append(element); - const self_closing = parser.eat('/') || is_void(name); + const self_closing = parser.eat('/') || is_void(tag.name); const closed = parser.eat('>', true, false); // Loose parsing mode @@ -382,7 +388,7 @@ export default function element(parser) { if (self_closing || !closed) { // don't push self-closing elements onto the stack element.end = parser.index; - } else if (name === 'textarea') { + } else if (tag.name === 'textarea') { // special case element.fragment.nodes = read_sequence( parser, @@ -391,10 +397,10 @@ export default function element(parser) { ); parser.read(regex_closing_textarea_tag); element.end = parser.index; - } else if (name === 'script' || name === 'style') { + } else if (tag.name === 'script' || tag.name === 'style') { // special case const start = parser.index; - const data = parser.read_until(new RegExp(``)); + const data = parser.read_until(new RegExp(``)); const end = parser.index; /** @type {AST.Text} */ @@ -407,7 +413,7 @@ export default function element(parser) { }; element.fragment.nodes.push(node); - parser.eat(``, true); + parser.eat(``, true); element.end = parser.index; } else { parser.stack.push(element); @@ -450,8 +456,8 @@ function parent_is_shadowroot_template(stack) { function read_static_attribute(parser) { const start = parser.index; - const name = parser.read_until(regex_token_ending_character); - if (!name) return null; + const tag = read_tag(parser, regex_token_ending_character); + if (!tag.name) return null; /** @type {true | Array} */ let value = true; @@ -485,7 +491,7 @@ function read_static_attribute(parser) { e.expected_token(parser.index, '='); } - return create_attribute(name, start, parser.index, value); + return create_attribute(tag.name, tag.loc, start, parser.index, value); } /** @@ -538,10 +544,9 @@ function read_attribute(parser) { return spread; } else { - const value_start = parser.index; - let name = parser.read_identifier(); + const id = parser.read_identifier(); - if (name === null) { + if (id.name === '') { if ( parser.loose && (parser.match('#') || parser.match('/') || parser.match('@') || parser.match(':')) @@ -551,7 +556,6 @@ function read_attribute(parser) { return null; } else if (parser.loose && parser.match('}')) { // Likely in the middle of typing, just created the shorthand - name = ''; } else { e.attribute_empty_shorthand(start); } @@ -563,32 +567,28 @@ function read_attribute(parser) { /** @type {AST.ExpressionTag} */ const expression = { type: 'ExpressionTag', - start: value_start, - end: value_start + name.length, - expression: { - start: value_start, - end: value_start + name.length, - type: 'Identifier', - name - }, + start: id.start, + end: id.end, + expression: id, metadata: { expression: new ExpressionMetadata() } }; - return create_attribute(name, start, parser.index, expression); + return create_attribute(id.name, id.loc, start, parser.index, expression); } } - const name = parser.read_until(regex_token_ending_character); - if (!name) return null; + const tag = read_tag(parser, regex_token_ending_character); + + if (!tag.name) return null; let end = parser.index; parser.allow_whitespace(); - const colon_index = name.indexOf(':'); - const type = colon_index !== -1 && get_directive_type(name.slice(0, colon_index)); + const colon_index = tag.name.indexOf(':'); + const type = colon_index !== -1 && get_directive_type(tag.name.slice(0, colon_index)); /** @type {true | AST.ExpressionTag | Array} */ let value = true; @@ -617,10 +617,10 @@ function read_attribute(parser) { } if (type) { - const [directive_name, ...modifiers] = name.slice(colon_index + 1).split('|'); + const [directive_name, ...modifiers] = tag.name.slice(colon_index + 1).split('|'); if (directive_name === '') { - e.directive_missing_name({ start, end: start + colon_index + 1 }, name); + e.directive_missing_name({ start, end: start + colon_index + 1 }, tag.name); } if (type === 'StyleDirective') { @@ -629,6 +629,7 @@ function read_attribute(parser) { end, type, name: directive_name, + name_loc: tag.loc, modifiers: /** @type {Array<'important'>} */ (modifiers), value, metadata: { @@ -659,6 +660,7 @@ function read_attribute(parser) { end, type, name: directive_name, + name_loc: tag.loc, expression, metadata: { expression: new ExpressionMetadata() @@ -669,7 +671,7 @@ function read_attribute(parser) { directive.modifiers = modifiers; if (directive.type === 'TransitionDirective') { - const direction = name.slice(0, colon_index); + const direction = tag.name.slice(0, colon_index); directive.intro = direction === 'in' || direction === 'transition'; directive.outro = direction === 'out' || direction === 'transition'; } @@ -690,7 +692,7 @@ function read_attribute(parser) { return directive; } - return create_attribute(name, start, end, value); + return create_attribute(tag.name, tag.loc, start, end, value); } /** @@ -851,3 +853,25 @@ function read_sequence(parser, done, location) { e.unexpected_eof(parser.template.length); } } + +/** + * @param {Parser} parser + * @param {RegExp} regex + * @returns {Identifier & { start: number, end: number, loc: SourceLocation }} + */ +function read_tag(parser, regex) { + const start = parser.index; + const name = parser.read_until(regex); + const end = parser.index; + + return { + type: 'Identifier', + name, + start, + end, + loc: { + start: locator(start), + end: locator(end) + } + }; +} diff --git a/packages/svelte/src/compiler/phases/1-parse/state/tag.js b/packages/svelte/src/compiler/phases/1-parse/state/tag.js index e6e083c09dc7..138eda8033d7 100644 --- a/packages/svelte/src/compiler/phases/1-parse/state/tag.js +++ b/packages/svelte/src/compiler/phases/1-parse/state/tag.js @@ -177,7 +177,7 @@ function open(parser) { if (parser.eat(',')) { parser.allow_whitespace(); - index = parser.read_identifier(); + index = parser.read_identifier().name; if (!index) { e.expected_identifier(parser.index); } @@ -347,16 +347,10 @@ function open(parser) { if (parser.eat('snippet')) { parser.require_whitespace(); - const name_start = parser.index; - let name = parser.read_identifier(); - const name_end = parser.index; + const id = parser.read_identifier(); - if (name === null) { - if (parser.loose) { - name = ''; - } else { - e.expected_identifier(parser.index); - } + if (id.name === '' && !parser.loose) { + e.expected_identifier(parser.index); } parser.allow_whitespace(); @@ -415,12 +409,7 @@ function open(parser) { type: 'SnippetBlock', start, end: -1, - expression: { - type: 'Identifier', - start: name_start, - end: name_end, - name - }, + expression: id, typeParams: type_params, parameters: function_expression.params, body: create_fragment(), diff --git a/packages/svelte/src/compiler/phases/2-analyze/index.js b/packages/svelte/src/compiler/phases/2-analyze/index.js index fb026fa78fd2..e44cf23ff5d2 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/index.js +++ b/packages/svelte/src/compiler/phases/2-analyze/index.js @@ -900,7 +900,7 @@ export function analyze_component(root, source, options) { // We need an empty class to generate the set_class() or class="" correctly if (!has_spread && !has_class && (node.metadata.scoped || has_class_directive)) { node.attributes.push( - create_attribute('class', -1, -1, [ + create_attribute('class', null, -1, -1, [ { type: 'Text', data: '', @@ -915,7 +915,7 @@ export function analyze_component(root, source, options) { // We need an empty style to generate the set_style() correctly if (!has_spread && !has_style && has_style_directive) { node.attributes.push( - create_attribute('style', -1, -1, [ + create_attribute('style', null, -1, -1, [ { type: 'Text', data: '', diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js index 4f41621db35b..5fce138089a9 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/RegularElement.js @@ -48,8 +48,9 @@ export function RegularElement(node, context) { node.attributes.push( create_attribute( 'value', - /** @type {AST.Text} */ (node.fragment.nodes.at(0)).start, - /** @type {AST.Text} */ (node.fragment.nodes.at(-1)).end, + null, + -1, + -1, // @ts-ignore node.fragment.nodes ) diff --git a/packages/svelte/src/compiler/phases/3-transform/client/transform-template/index.js b/packages/svelte/src/compiler/phases/3-transform/client/transform-template/index.js index d0327e702ad5..40c0907e3857 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/transform-template/index.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/transform-template/index.js @@ -1,4 +1,3 @@ -/** @import { Location } from 'locate-character' */ /** @import { Namespace } from '#compiler' */ /** @import { ComponentClientTransformState } from '../types.js' */ /** @import { Node } from './types.js' */ @@ -15,7 +14,7 @@ function build_locations(nodes) { for (const node of nodes) { if (node.type !== 'element') continue; - const { line, column } = /** @type {Location} */ (locator(node.start)); + const { line, column } = locator(node.start); const expression = b.array([b.literal(line), b.literal(column)]); const children = build_locations(node.children); diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/BindDirective.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/BindDirective.js index 12118d9f692c..6838e5006db0 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/BindDirective.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/BindDirective.js @@ -40,22 +40,38 @@ export function BindDirective(node, context) { validate_binding(context.state, node, expression); } - get = b.thunk(expression); + const assignment = /** @type {Expression} */ ( + context.visit(b.assignment('=', /** @type {Pattern} */ (node.expression), b.id('$$value'))) + ); - /** @type {Expression | undefined} */ - set = b.unthunk( - b.arrow( + if (dev) { + // in dev, create named functions, so that `$inspect(...)` delivers + // useful stack traces + get = b.function(b.id('get', node.name_loc), [], b.block([b.return(expression)])); + set = b.function( + b.id('set', node.name_loc), [b.id('$$value')], - /** @type {Expression} */ ( - context.visit( - b.assignment('=', /** @type {Pattern} */ (node.expression), b.id('$$value')) + b.block([b.stmt(assignment)]) + ); + } else { + // in prod, optimise for brevity + get = b.thunk(expression); + + /** @type {Expression | undefined} */ + set = b.unthunk( + b.arrow( + [b.id('$$value')], + /** @type {Expression} */ ( + context.visit( + b.assignment('=', /** @type {Pattern} */ (node.expression), b.id('$$value')) + ) ) ) - ) - ); + ); - if (get === set) { - set = undefined; + if (get === set) { + set = undefined; + } } } diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/CallExpression.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/CallExpression.js index e7468291a05c..f69bc5fe6e8d 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/CallExpression.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/CallExpression.js @@ -39,7 +39,8 @@ export function CallExpression(node, context) { } } - return b.call('$.state', value); + const callee = b.id('$.state', node.callee.loc); + return b.call(callee, value); } case '$derived': diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/Component.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/Component.js index 9b86557536d0..12c7b2142b73 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/Component.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/Component.js @@ -1,6 +1,5 @@ /** @import { AST } from '#compiler' */ /** @import { ComponentContext } from '../types' */ -import { regex_is_valid_identifier } from '../../../patterns.js'; import { build_component } from './shared/component.js'; /** @@ -8,6 +7,6 @@ import { build_component } from './shared/component.js'; * @param {ComponentContext} context */ export function Component(node, context) { - const component = build_component(node, node.name, context); + const component = build_component(node, node.name, node.name_loc, context); context.state.init.push(component); } diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/Fragment.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/Fragment.js index ff2436779b92..18017ea557a4 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/Fragment.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/Fragment.js @@ -81,7 +81,7 @@ export function Fragment(node, context) { if (is_single_element) { const element = /** @type {AST.RegularElement} */ (trimmed[0]); - const id = b.id(context.state.scope.generate(element.name)); + const id = b.id(context.state.scope.generate(element.name), element.name_loc); context.visit(element, { ...state, diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js index 971f93e1d8f8..50cef67171d7 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js @@ -407,6 +407,7 @@ export function RegularElement(node, context) { const synthetic_node = node.metadata.synthetic_value_node; const synthetic_attribute = create_attribute( 'value', + null, synthetic_node.start, synthetic_node.end, [synthetic_node] diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteComponent.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteComponent.js index 85a4b611c013..d6a0418dd041 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteComponent.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteComponent.js @@ -1,12 +1,13 @@ /** @import { AST } from '#compiler' */ /** @import { ComponentContext } from '../types' */ import { build_component } from './shared/component.js'; +import * as b from '#compiler/builders'; /** * @param {AST.SvelteComponent} node * @param {ComponentContext} context */ export function SvelteComponent(node, context) { - const component = build_component(node, '$$component', context); + const component = build_component(node, '$$component', null, context); context.state.init.push(component); } diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteHead.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteHead.js index 3a45389dd73d..f57e333a3571 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteHead.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteHead.js @@ -14,7 +14,7 @@ export function SvelteHead(node, context) { context.state.init.push( b.stmt( b.call( - '$.head', + b.id('$.head', node.name_loc), b.literal(hash(filename)), b.arrow([b.id('$$anchor')], /** @type {BlockStatement} */ (context.visit(node.fragment))) ) diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteSelf.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteSelf.js index 285951499caf..3d076177acc0 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteSelf.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/SvelteSelf.js @@ -1,5 +1,6 @@ /** @import { AST } from '#compiler' */ /** @import { ComponentContext } from '../types' */ +import { component_name } from '../../../../state.js'; import { build_component } from './shared/component.js'; /** @@ -7,6 +8,6 @@ import { build_component } from './shared/component.js'; * @param {ComponentContext} context */ export function SvelteSelf(node, context) { - const component = build_component(node, context.state.analysis.name, context); + const component = build_component(node, component_name, node.name_loc, context); context.state.init.push(component); } diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/TitleElement.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/TitleElement.js index f815f3ae0576..d91c3874966c 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/TitleElement.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/TitleElement.js @@ -20,7 +20,7 @@ export function TitleElement(node, context) { const statement = b.stmt( b.assignment( '=', - b.id('$.document.title'), + b.member(b.id('$.document'), b.id('title', node.name_loc)), evaluated.is_known ? b.literal(evaluated.value) : evaluated.is_defined diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js index f830e8c57d88..57dba202baf2 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/VariableDeclaration.js @@ -136,7 +136,8 @@ export function VariableDeclaration(node, context) { } if (is_state) { - value = b.call('$.state', value); + const callee = b.id('$.state', /** @type {CallExpression} */ (init).callee.loc); + value = b.call(callee, value); if (dev) { value = b.call('$.tag', value, b.literal(id.name)); diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js index d70048ad7eb9..4651f6f733e9 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/component.js @@ -1,4 +1,4 @@ -/** @import { BlockStatement, Expression, ExpressionStatement, Identifier, MemberExpression, Pattern, Property, SequenceExpression, Statement } from 'estree' */ +/** @import { BlockStatement, Expression, ExpressionStatement, Identifier, MemberExpression, Pattern, Property, SequenceExpression, SourceLocation, Statement } from 'estree' */ /** @import { AST } from '#compiler' */ /** @import { ComponentContext } from '../../types.js' */ import { dev, is_ignored } from '../../../../../state.js'; @@ -12,10 +12,11 @@ import { determine_slot } from '../../../../../utils/slot.js'; /** * @param {AST.Component | AST.SvelteComponent | AST.SvelteSelf} node * @param {string} component_name + * @param {SourceLocation | null} loc * @param {ComponentContext} context * @returns {Statement} */ -export function build_component(node, component_name, context) { +export function build_component(node, component_name, loc, context) { /** @type {Expression} */ const anchor = context.state.node; @@ -259,15 +260,9 @@ export function build_component(node, component_name, context) { attribute.expression.type === 'Identifier' && context.state.scope.get(attribute.expression.name)?.kind === 'store_sub'; - // Delay prop pushes so bindings come at the end, to avoid spreads overwriting them - if (is_store_sub) { - push_prop( - b.get(attribute.name, [b.stmt(b.call('$.mark_store_binding')), b.return(expression)]), - true - ); - } else { - push_prop(b.get(attribute.name, [b.return(expression)]), true); - } + const get = is_store_sub + ? b.get(attribute.name, [b.stmt(b.call('$.mark_store_binding')), b.return(expression)]) + : b.get(attribute.name, [b.return(expression)]); const assignment = b.assignment( '=', @@ -275,10 +270,16 @@ export function build_component(node, component_name, context) { b.id('$$value') ); - push_prop( - b.set(attribute.name, [b.stmt(/** @type {Expression} */ (context.visit(assignment)))]), - true - ); + const set = b.set(attribute.name, [ + b.stmt(/** @type {Expression} */ (context.visit(assignment))) + ]); + + get.key.loc = attribute.name_loc; + set.key.loc = attribute.name_loc; + + // Delay prop pushes so bindings come at the end, to avoid spreads overwriting them + push_prop(get, true); + push_prop(set, true); } } } else if (attribute.type === 'AttachTag') { @@ -434,16 +435,17 @@ export function build_component(node, component_name, context) { /** @param {Expression} node_id */ let fn = (node_id) => { - return b.call( - // TODO We can remove this ternary once we remove legacy mode, since in runes mode dynamic components - // will be handled separately through the `$.component` function, and then the component name will - // always be referenced through just the identifier here. - is_component_dynamic - ? intermediate_name - : /** @type {Expression} */ (context.visit(b.member_id(component_name))), - node_id, - props_expression - ); + // TODO We can remove this ternary once we remove legacy mode, since in runes mode dynamic components + // will be handled separately through the `$.component` function, and then the component name will + // always be referenced through just the identifier here. + const callee = is_component_dynamic + ? b.id(intermediate_name) + : /** @type {Expression} */ (context.visit(b.member_id(component_name))); + + // line up the `Foo` in `Foo(...)` and `` for usable stack traces + callee.loc = loc; + + return b.call(callee, node_id, props_expression); }; if (bind_this !== null) { diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/events.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/events.js index 3ab1506eb39e..29edc316ca8d 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/events.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/events.js @@ -32,7 +32,13 @@ export function visit_event_attribute(node, context) { } context.state.init.push( - b.stmt(b.assignment('=', b.member(context.state.node, '__' + event_name), handler)) + b.stmt( + b.assignment( + '=', + b.member(context.state.node, b.id('__' + event_name, node.name_loc)), + handler + ) + ) ); } else { const statement = b.stmt( @@ -140,7 +146,7 @@ export function build_event_handler(node, metadata, context) { b.this, b.id('$$args'), b.id(context.state.analysis.name), - loc && b.array([b.literal(loc.line), b.literal(loc.column)]), + b.array([b.literal(loc.line), b.literal(loc.column)]), has_side_effects(node) && b.true, remove_parens && b.true ); diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js index 67982b6150b7..ff931842d89c 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/fragment.js @@ -1,4 +1,4 @@ -/** @import { Expression } from 'estree' */ +/** @import { Expression, Identifier, SourceLocation } from 'estree' */ /** @import { AST } from '#compiler' */ /** @import { ComponentContext } from '../../types' */ import { cannot_be_set_statically } from '../../../../../../utils.js'; @@ -42,13 +42,14 @@ export function process_children(nodes, initial, is_element, context) { /** * @param {boolean} is_text * @param {string} name + * @param {SourceLocation | null} [loc] */ - function flush_node(is_text, name) { + function flush_node(is_text, name, loc) { const expression = get_node(is_text); let id = expression; if (id.type !== 'Identifier') { - id = b.id(context.state.scope.generate(name)); + id = b.id(context.state.scope.generate(name), loc); context.state.init.push(b.var(id, expression)); } @@ -109,7 +110,12 @@ export function process_children(nodes, initial, is_element, context) { ) { node.metadata.is_controlled = true; } else { - const id = flush_node(false, node.type === 'RegularElement' ? node.name : 'node'); + const id = flush_node( + false, + node.type === 'RegularElement' ? node.name : 'node', + node.type === 'RegularElement' ? node.name_loc : null + ); + child_state = { ...context.state, node: id }; } diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js index e7a4f6059b33..6145f66d8769 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/shared/utils.js @@ -366,8 +366,8 @@ export function validate_binding(state, binding, expression) { : b.literal(/** @type {Identifier} */ (expression.property).name) ) ), - loc && b.literal(loc.line), - loc && b.literal(loc.column) + b.literal(loc.line), + b.literal(loc.column) ) ) ); diff --git a/packages/svelte/src/compiler/phases/3-transform/server/visitors/RegularElement.js b/packages/svelte/src/compiler/phases/3-transform/server/visitors/RegularElement.js index 2ca16c4a2465..f74b1185a069 100644 --- a/packages/svelte/src/compiler/phases/3-transform/server/visitors/RegularElement.js +++ b/packages/svelte/src/compiler/phases/3-transform/server/visitors/RegularElement.js @@ -99,7 +99,7 @@ export function RegularElement(node, context) { } if (dev) { - const location = /** @type {Location} */ (locator(node.start)); + const location = locator(node.start); state.template.push( b.stmt( b.call( diff --git a/packages/svelte/src/compiler/phases/3-transform/server/visitors/SvelteElement.js b/packages/svelte/src/compiler/phases/3-transform/server/visitors/SvelteElement.js index 145167a690f2..6fc1ca5dfc3a 100644 --- a/packages/svelte/src/compiler/phases/3-transform/server/visitors/SvelteElement.js +++ b/packages/svelte/src/compiler/phases/3-transform/server/visitors/SvelteElement.js @@ -50,7 +50,7 @@ export function SvelteElement(node, context) { build_element_attributes(node, { ...context, state }, optimiser.transform); if (dev) { - const location = /** @type {Location} */ (locator(node.start)); + const location = locator(node.start); statements.push( b.stmt( b.call( diff --git a/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js b/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js index 31ffe1913992..979efef6b9c4 100644 --- a/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js +++ b/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js @@ -142,7 +142,7 @@ export function build_element_attributes(node, context, transform) { ); attributes.push( - create_attribute('checked', -1, -1, [ + create_attribute('checked', null, -1, -1, [ { type: 'ExpressionTag', start: -1, @@ -165,7 +165,7 @@ export function build_element_attributes(node, context, transform) { ); } else { attributes.push( - create_attribute(attribute.name, -1, -1, [ + create_attribute(attribute.name, null, -1, -1, [ { type: 'ExpressionTag', start: -1, diff --git a/packages/svelte/src/compiler/phases/nodes.js b/packages/svelte/src/compiler/phases/nodes.js index e9717eb4048a..313880cf5b65 100644 --- a/packages/svelte/src/compiler/phases/nodes.js +++ b/packages/svelte/src/compiler/phases/nodes.js @@ -1,4 +1,4 @@ -/** @import { Expression, PrivateIdentifier } from 'estree' */ +/** @import { Expression, PrivateIdentifier, SourceLocation } from 'estree' */ /** @import { AST, Binding } from '#compiler' */ import * as b from '#compiler/builders'; @@ -47,17 +47,19 @@ export function is_custom_element_node(node) { /** * @param {string} name + * @param {SourceLocation | null} name_loc * @param {number} start * @param {number} end * @param {AST.Attribute['value']} value * @returns {AST.Attribute} */ -export function create_attribute(name, start, end, value) { +export function create_attribute(name, name_loc, start, end, value) { return { type: 'Attribute', start, end, name, + name_loc, value, metadata: { delegated: false, diff --git a/packages/svelte/src/compiler/state.js b/packages/svelte/src/compiler/state.js index 6d9873eb301e..37aeafe5952e 100644 --- a/packages/svelte/src/compiler/state.js +++ b/packages/svelte/src/compiler/state.js @@ -40,19 +40,28 @@ export let dev; export let runes = false; -export let locator = getLocator('', { offsetLine: 1 }); +/** @type {(index: number) => Location} */ +export let locator; /** @param {string} value */ export function set_source(value) { source = value; - locator = getLocator(source, { offsetLine: 1 }); + + const l = getLocator(source, { offsetLine: 1 }); + + locator = (i) => { + const loc = l(i); + if (!loc) throw new Error('An impossible situation occurred'); + + return loc; + }; } /** * @param {AST.SvelteNode & { start?: number | undefined }} node */ export function locate_node(node) { - const loc = /** @type {Location} */ (locator(/** @type {number} */ (node.start))); + const loc = locator(/** @type {number} */ (node.start)); return `${sanitize_location(filename)}:${loc?.line}:${loc.column}`; } @@ -103,7 +112,6 @@ export function reset(state) { runes = false; component_name = UNKNOWN_FILENAME; source = ''; - locator = () => undefined; filename = (state.filename ?? UNKNOWN_FILENAME).replace(/\\/g, '/'); warning_filter = state.warning ?? (() => true); warnings = []; diff --git a/packages/svelte/src/compiler/types/template.d.ts b/packages/svelte/src/compiler/types/template.d.ts index c06b77c53cd9..b529a2dda9f6 100644 --- a/packages/svelte/src/compiler/types/template.d.ts +++ b/packages/svelte/src/compiler/types/template.d.ts @@ -13,7 +13,8 @@ import type { Program, ChainExpression, SimpleCallExpression, - SequenceExpression + SequenceExpression, + SourceLocation } from 'estree'; import type { Scope } from '../phases/scope'; import type { _CSS } from './css'; @@ -188,7 +189,7 @@ export namespace AST { } /** An `animate:` directive */ - export interface AnimateDirective extends BaseNode { + export interface AnimateDirective extends BaseAttribute { type: 'AnimateDirective'; /** The 'x' in `animate:x` */ name: string; @@ -201,7 +202,7 @@ export namespace AST { } /** A `bind:` directive */ - export interface BindDirective extends BaseNode { + export interface BindDirective extends BaseAttribute { type: 'BindDirective'; /** The 'x' in `bind:x` */ name: string; @@ -217,7 +218,7 @@ export namespace AST { } /** A `class:` directive */ - export interface ClassDirective extends BaseNode { + export interface ClassDirective extends BaseAttribute { type: 'ClassDirective'; /** The 'x' in `class:x` */ name: 'class'; @@ -230,7 +231,7 @@ export namespace AST { } /** A `let:` directive */ - export interface LetDirective extends BaseNode { + export interface LetDirective extends BaseAttribute { type: 'LetDirective'; /** The 'x' in `let:x` */ name: string; @@ -239,7 +240,7 @@ export namespace AST { } /** An `on:` directive */ - export interface OnDirective extends BaseNode { + export interface OnDirective extends BaseAttribute { type: 'OnDirective'; /** The 'x' in `on:x` */ name: string; @@ -263,7 +264,7 @@ export namespace AST { } /** A `style:` directive */ - export interface StyleDirective extends BaseNode { + export interface StyleDirective extends BaseAttribute { type: 'StyleDirective'; /** The 'x' in `style:x` */ name: string; @@ -278,7 +279,7 @@ export namespace AST { // TODO have separate in/out/transition directives /** A `transition:`, `in:` or `out:` directive */ - export interface TransitionDirective extends BaseNode { + export interface TransitionDirective extends BaseAttribute { type: 'TransitionDirective'; /** The 'x' in `transition:x` */ name: string; @@ -296,7 +297,7 @@ export namespace AST { } /** A `use:` directive */ - export interface UseDirective extends BaseNode { + export interface UseDirective extends BaseAttribute { type: 'UseDirective'; /** The 'x' in `use:x` */ name: string; @@ -310,6 +311,7 @@ export namespace AST { export interface BaseElement extends BaseNode { name: string; + name_loc: SourceLocation; attributes: Array; fragment: Fragment; } @@ -528,9 +530,13 @@ export namespace AST { }; } - export interface Attribute extends BaseNode { - type: 'Attribute'; + export interface BaseAttribute extends BaseNode { name: string; + name_loc: SourceLocation | null; + } + + export interface Attribute extends BaseAttribute { + type: 'Attribute'; /** * Quoted/string values are represented by an array, even if they contain a single expression like `"{x}"` */ diff --git a/packages/svelte/src/compiler/utils/builders.js b/packages/svelte/src/compiler/utils/builders.js index 82fce262b9d9..223676d22ff0 100644 --- a/packages/svelte/src/compiler/utils/builders.js +++ b/packages/svelte/src/compiler/utils/builders.js @@ -262,10 +262,14 @@ export function get(name, body) { /** * @param {string} name + * @param {ESTree.SourceLocation | null} [loc] * @returns {ESTree.Identifier} */ -export function id(name) { - return { type: 'Identifier', name }; +export function id(name, loc) { + const node = /** @type {ESTree.Identifier} */ ({ type: 'Identifier', name }); + if (loc) node.loc = loc; + + return node; } /** diff --git a/packages/svelte/tests/parser-legacy/samples/action-duplicate/output.json b/packages/svelte/tests/parser-legacy/samples/action-duplicate/output.json index 2318720f79a0..9a171547fe7d 100644 --- a/packages/svelte/tests/parser-legacy/samples/action-duplicate/output.json +++ b/packages/svelte/tests/parser-legacy/samples/action-duplicate/output.json @@ -15,6 +15,18 @@ "end": 20, "type": "Action", "name": "autofocus", + "name_loc": { + "start": { + "line": 1, + "column": 7, + "character": 7 + }, + "end": { + "line": 1, + "column": 20, + "character": 20 + } + }, "expression": null, "modifiers": [] }, @@ -23,6 +35,18 @@ "end": 34, "type": "Action", "name": "autofocus", + "name_loc": { + "start": { + "line": 1, + "column": 21, + "character": 21 + }, + "end": { + "line": 1, + "column": 34, + "character": 34 + } + }, "expression": null, "modifiers": [] } @@ -31,4 +55,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/action-with-call/output.json b/packages/svelte/tests/parser-legacy/samples/action-with-call/output.json index f2ef97f14574..f3242eba5eb4 100644 --- a/packages/svelte/tests/parser-legacy/samples/action-with-call/output.json +++ b/packages/svelte/tests/parser-legacy/samples/action-with-call/output.json @@ -15,6 +15,18 @@ "end": 39, "type": "Action", "name": "tooltip", + "name_loc": { + "start": { + "line": 1, + "column": 7, + "character": 7 + }, + "end": { + "line": 1, + "column": 18, + "character": 18 + } + }, "expression": { "type": "CallExpression", "start": 21, @@ -73,4 +85,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/action-with-identifier/output.json b/packages/svelte/tests/parser-legacy/samples/action-with-identifier/output.json index d6f14ad053d4..8f76afc829cb 100644 --- a/packages/svelte/tests/parser-legacy/samples/action-with-identifier/output.json +++ b/packages/svelte/tests/parser-legacy/samples/action-with-identifier/output.json @@ -15,6 +15,18 @@ "end": 28, "type": "Action", "name": "tooltip", + "name_loc": { + "start": { + "line": 1, + "column": 7, + "character": 7 + }, + "end": { + "line": 1, + "column": 18, + "character": 18 + } + }, "expression": { "type": "Identifier", "start": 20, @@ -38,4 +50,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/action-with-literal/output.json b/packages/svelte/tests/parser-legacy/samples/action-with-literal/output.json index 240f80df091a..b6c4f2690d4f 100644 --- a/packages/svelte/tests/parser-legacy/samples/action-with-literal/output.json +++ b/packages/svelte/tests/parser-legacy/samples/action-with-literal/output.json @@ -15,6 +15,18 @@ "end": 36, "type": "Action", "name": "tooltip", + "name_loc": { + "start": { + "line": 1, + "column": 7, + "character": 7 + }, + "end": { + "line": 1, + "column": 18, + "character": 18 + } + }, "expression": { "type": "Literal", "start": 21, @@ -39,4 +51,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/action/output.json b/packages/svelte/tests/parser-legacy/samples/action/output.json index 0e5d8775849b..a27177898586 100644 --- a/packages/svelte/tests/parser-legacy/samples/action/output.json +++ b/packages/svelte/tests/parser-legacy/samples/action/output.json @@ -15,6 +15,18 @@ "end": 20, "type": "Action", "name": "autofocus", + "name_loc": { + "start": { + "line": 1, + "column": 7, + "character": 7 + }, + "end": { + "line": 1, + "column": 20, + "character": 20 + } + }, "expression": null, "modifiers": [] } @@ -23,4 +35,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/animation/output.json b/packages/svelte/tests/parser-legacy/samples/animation/output.json index 4b4700dd98b6..262bb17d9a37 100644 --- a/packages/svelte/tests/parser-legacy/samples/animation/output.json +++ b/packages/svelte/tests/parser-legacy/samples/animation/output.json @@ -20,6 +20,18 @@ "end": 50, "type": "Animation", "name": "flip", + "name_loc": { + "start": { + "line": 2, + "column": 6, + "character": 38 + }, + "end": { + "line": 2, + "column": 18, + "character": 50 + } + }, "expression": null, "modifiers": [] } @@ -39,6 +51,7 @@ "type": "Identifier", "name": "thing", "start": 17, + "end": 22, "loc": { "start": { "line": 1, @@ -50,8 +63,7 @@ "column": 22, "character": 22 } - }, - "end": 22 + } }, "expression": { "type": "Identifier", @@ -88,4 +100,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-class-directive/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-class-directive/output.json index 2585fcfe9403..bbf9c12ceba1 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-class-directive/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-class-directive/output.json @@ -15,6 +15,18 @@ "end": 22, "type": "Class", "name": "foo", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 14, + "character": 14 + } + }, "expression": { "type": "Identifier", "start": 16, @@ -38,4 +50,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-containing-solidus/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-containing-solidus/output.json index c67811fab964..c1bcbbaf5eb8 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-containing-solidus/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-containing-solidus/output.json @@ -15,6 +15,18 @@ "start": 3, "end": 30, "name": "href", + "name_loc": { + "start": { + "line": 1, + "column": 3, + "character": 3 + }, + "end": { + "line": 1, + "column": 7, + "character": 7 + } + }, "value": [ { "start": 8, @@ -38,4 +50,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-curly-bracket/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-curly-bracket/output.json index a137dd795b3f..d84b63745cbb 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-curly-bracket/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-curly-bracket/output.json @@ -15,6 +15,18 @@ "start": 7, "end": 15, "name": "foo", + "name_loc": { + "start": { + "line": 1, + "column": 7, + "character": 7 + }, + "end": { + "line": 1, + "column": 10, + "character": 10 + } + }, "value": [ { "start": 11, @@ -52,4 +64,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-dynamic-boolean/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-dynamic-boolean/output.json index 5462eaf71333..13488a20d3db 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-dynamic-boolean/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-dynamic-boolean/output.json @@ -15,6 +15,18 @@ "start": 10, "end": 29, "name": "readonly", + "name_loc": { + "start": { + "line": 1, + "column": 10, + "character": 10 + }, + "end": { + "line": 1, + "column": 18, + "character": 18 + } + }, "value": [ { "type": "MustacheTag", @@ -44,4 +56,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-dynamic/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-dynamic/output.json index 6acc5ebeb133..088a9d01ab1d 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-dynamic/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-dynamic/output.json @@ -15,6 +15,18 @@ "start": 5, "end": 28, "name": "style", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 10, + "character": 10 + } + }, "value": [ { "start": 12, @@ -80,4 +92,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-empty/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-empty/output.json index 478ba2e52560..028b11077dc8 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-empty/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-empty/output.json @@ -15,6 +15,18 @@ "start": 5, "end": 9, "name": "a", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 6, + "character": 6 + } + }, "value": [ { "start": 8, @@ -30,6 +42,18 @@ "start": 10, "end": 16, "name": "b", + "name_loc": { + "start": { + "line": 1, + "column": 10, + "character": 10 + }, + "end": { + "line": 1, + "column": 11, + "character": 11 + } + }, "value": [ { "type": "MustacheTag", @@ -60,6 +84,18 @@ "start": 17, "end": 21, "name": "c", + "name_loc": { + "start": { + "line": 1, + "column": 17, + "character": 17 + }, + "end": { + "line": 1, + "column": 18, + "character": 18 + } + }, "value": [ { "start": 20, @@ -75,6 +111,18 @@ "start": 22, "end": 30, "name": "d", + "name_loc": { + "start": { + "line": 1, + "column": 22, + "character": 22 + }, + "end": { + "line": 1, + "column": 23, + "character": 23 + } + }, "value": [ { "type": "MustacheTag", @@ -105,4 +153,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-escaped/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-escaped/output.json index 74fa6f2aec1b..a23fcd55cd1a 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-escaped/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-escaped/output.json @@ -15,6 +15,18 @@ "start": 5, "end": 76, "name": "data-foo", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 13, + "character": 13 + } + }, "value": [ { "start": 15, @@ -30,4 +42,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-multiple/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-multiple/output.json index 80bbdf0e21ed..4e2bddf54ee9 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-multiple/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-multiple/output.json @@ -15,6 +15,18 @@ "start": 5, "end": 11, "name": "id", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 7, + "character": 7 + } + }, "value": [ { "start": 9, @@ -30,6 +42,18 @@ "start": 12, "end": 21, "name": "class", + "name_loc": { + "start": { + "line": 1, + "column": 12, + "character": 12 + }, + "end": { + "line": 1, + "column": 17, + "character": 17 + } + }, "value": [ { "start": 19, @@ -45,4 +69,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-shorthand/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-shorthand/output.json index 87a01d4b09f3..61121e436e3d 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-shorthand/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-shorthand/output.json @@ -15,16 +15,40 @@ "start": 5, "end": 9, "name": "id", + "name_loc": { + "start": { + "line": 1, + "column": 6, + "character": 6 + }, + "end": { + "line": 1, + "column": 8, + "character": 8 + } + }, "value": [ { "type": "AttributeShorthand", "start": 6, "end": 8, "expression": { + "type": "Identifier", + "name": "id", "start": 6, "end": 8, - "type": "Identifier", - "name": "id" + "loc": { + "start": { + "line": 1, + "column": 6, + "character": 6 + }, + "end": { + "line": 1, + "column": 8, + "character": 8 + } + } } } ] @@ -34,4 +58,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-static-boolean/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-static-boolean/output.json index a059934e4075..1442a445d0ca 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-static-boolean/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-static-boolean/output.json @@ -15,6 +15,18 @@ "start": 10, "end": 18, "name": "readonly", + "name_loc": { + "start": { + "line": 1, + "column": 10, + "character": 10 + }, + "end": { + "line": 1, + "column": 18, + "character": 18 + } + }, "value": true } ], @@ -22,4 +34,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-static/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-static/output.json index 94608a0eba0e..dbc2a4b79f97 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-static/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-static/output.json @@ -15,6 +15,18 @@ "start": 5, "end": 16, "name": "class", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 10, + "character": 10 + } + }, "value": [ { "start": 12, @@ -30,4 +42,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-style-directive-modifiers/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-style-directive-modifiers/output.json index 45bb6f0e2ec8..da8a11e48e43 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-style-directive-modifiers/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-style-directive-modifiers/output.json @@ -15,6 +15,18 @@ "end": 36, "type": "StyleDirective", "name": "color", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 26, + "character": 26 + } + }, "modifiers": [ "important" ], @@ -47,4 +59,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-style-directive-shorthand/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-style-directive-shorthand/output.json index 4ad7aaf7f78b..b54a6e91d70c 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-style-directive-shorthand/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-style-directive-shorthand/output.json @@ -15,6 +15,18 @@ "end": 16, "type": "StyleDirective", "name": "color", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 16, + "character": 16 + } + }, "modifiers": [], "value": true } @@ -23,4 +35,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-style-directive-string/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-style-directive-string/output.json index 9693f9778275..f349e61ef73b 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-style-directive-string/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-style-directive-string/output.json @@ -15,6 +15,18 @@ "end": 22, "type": "StyleDirective", "name": "color", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 16, + "character": 16 + } + }, "modifiers": [], "value": [ { @@ -47,6 +59,18 @@ "end": 52, "type": "StyleDirective", "name": "color", + "name_loc": { + "start": { + "line": 2, + "column": 5, + "character": 35 + }, + "end": { + "line": 2, + "column": 16, + "character": 46 + } + }, "modifiers": [], "value": [ { @@ -79,6 +103,18 @@ "end": 80, "type": "StyleDirective", "name": "color", + "name_loc": { + "start": { + "line": 3, + "column": 5, + "character": 65 + }, + "end": { + "line": 3, + "column": 16, + "character": 76 + } + }, "modifiers": [], "value": [ { @@ -111,6 +147,18 @@ "end": 120, "type": "StyleDirective", "name": "color", + "name_loc": { + "start": { + "line": 4, + "column": 5, + "character": 93 + }, + "end": { + "line": 4, + "column": 16, + "character": 104 + } + }, "modifiers": [], "value": [ { @@ -164,6 +212,18 @@ "end": 160, "type": "StyleDirective", "name": "color", + "name_loc": { + "start": { + "line": 5, + "column": 5, + "character": 133 + }, + "end": { + "line": 5, + "column": 16, + "character": 144 + } + }, "modifiers": [], "value": [ { @@ -217,6 +277,18 @@ "end": 198, "type": "StyleDirective", "name": "color", + "name_loc": { + "start": { + "line": 6, + "column": 5, + "character": 173 + }, + "end": { + "line": 6, + "column": 16, + "character": 184 + } + }, "modifiers": [], "value": [ { @@ -270,6 +342,18 @@ "end": 245, "type": "StyleDirective", "name": "color", + "name_loc": { + "start": { + "line": 7, + "column": 5, + "character": 211 + }, + "end": { + "line": 7, + "column": 16, + "character": 222 + } + }, "modifiers": [], "value": [ { @@ -359,4 +443,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-style-directive/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-style-directive/output.json index 08e2032db321..34e899428ce2 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-style-directive/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-style-directive/output.json @@ -15,6 +15,18 @@ "end": 26, "type": "StyleDirective", "name": "color", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 16, + "character": 16 + } + }, "modifiers": [], "value": [ { @@ -45,4 +57,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-style/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-style/output.json index d029f9ef7108..272c48d6ed32 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-style/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-style/output.json @@ -15,6 +15,18 @@ "start": 5, "end": 24, "name": "style", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 10, + "character": 10 + } + }, "value": [ { "start": 12, @@ -38,4 +50,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-unquoted/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-unquoted/output.json index a8fb61f58c37..fecbd9f2903b 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-unquoted/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-unquoted/output.json @@ -15,6 +15,18 @@ "start": 5, "end": 14, "name": "class", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 10, + "character": 10 + } + }, "value": [ { "start": 11, @@ -46,6 +58,18 @@ "start": 25, "end": 31, "name": "href", + "name_loc": { + "start": { + "line": 2, + "column": 3, + "character": 25 + }, + "end": { + "line": 2, + "column": 7, + "character": 29 + } + }, "value": [ { "start": 30, @@ -85,6 +109,18 @@ "start": 44, "end": 53, "name": "href", + "name_loc": { + "start": { + "line": 3, + "column": 3, + "character": 44 + }, + "end": { + "line": 3, + "column": 7, + "character": 48 + } + }, "value": [ { "start": 49, @@ -108,4 +144,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/attribute-with-whitespace/output.json b/packages/svelte/tests/parser-legacy/samples/attribute-with-whitespace/output.json index 174e2b174f72..16cfcec195b9 100644 --- a/packages/svelte/tests/parser-legacy/samples/attribute-with-whitespace/output.json +++ b/packages/svelte/tests/parser-legacy/samples/attribute-with-whitespace/output.json @@ -15,6 +15,18 @@ "end": 23, "type": "EventHandler", "name": "click", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 16, + "character": 16 + } + }, "expression": { "type": "Identifier", "start": 19, @@ -46,4 +58,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/await-catch/output.json b/packages/svelte/tests/parser-legacy/samples/await-catch/output.json index 5c2fa74e425e..1ac7f1773d48 100644 --- a/packages/svelte/tests/parser-legacy/samples/await-catch/output.json +++ b/packages/svelte/tests/parser-legacy/samples/await-catch/output.json @@ -29,6 +29,7 @@ "type": "Identifier", "name": "theError", "start": 47, + "end": 55, "loc": { "start": { "line": 3, @@ -40,8 +41,7 @@ "column": 16, "character": 55 } - }, - "end": 55 + } }, "pending": { "type": "PendingBlock", @@ -183,4 +183,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/await-then-catch/output.json b/packages/svelte/tests/parser-legacy/samples/await-then-catch/output.json index 5548cfc22eb5..df76eab8d3e9 100644 --- a/packages/svelte/tests/parser-legacy/samples/await-then-catch/output.json +++ b/packages/svelte/tests/parser-legacy/samples/await-then-catch/output.json @@ -28,6 +28,7 @@ "type": "Identifier", "name": "theValue", "start": 46, + "end": 54, "loc": { "start": { "line": 3, @@ -39,13 +40,13 @@ "column": 15, "character": 54 } - }, - "end": 54 + } }, "error": { "type": "Identifier", "name": "theError", "start": 96, + "end": 104, "loc": { "start": { "line": 5, @@ -57,8 +58,7 @@ "column": 16, "character": 104 } - }, - "end": 104 + } }, "pending": { "type": "PendingBlock", @@ -252,4 +252,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/binding-shorthand/output.json b/packages/svelte/tests/parser-legacy/samples/binding-shorthand/output.json index 61065609496c..9c48025ff9b6 100644 --- a/packages/svelte/tests/parser-legacy/samples/binding-shorthand/output.json +++ b/packages/svelte/tests/parser-legacy/samples/binding-shorthand/output.json @@ -22,6 +22,18 @@ "end": 46, "type": "Binding", "name": "foo", + "name_loc": { + "start": { + "line": 5, + "column": 8, + "character": 38 + }, + "end": { + "line": 5, + "column": 16, + "character": 46 + } + }, "expression": { "start": 43, "end": 46, @@ -109,4 +121,4 @@ "sourceType": "module" } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/binding/output.json b/packages/svelte/tests/parser-legacy/samples/binding/output.json index b6d24d6579d0..17a78f051c1f 100644 --- a/packages/svelte/tests/parser-legacy/samples/binding/output.json +++ b/packages/svelte/tests/parser-legacy/samples/binding/output.json @@ -22,6 +22,18 @@ "end": 55, "type": "Binding", "name": "value", + "name_loc": { + "start": { + "line": 5, + "column": 7, + "character": 38 + }, + "end": { + "line": 5, + "column": 17, + "character": 48 + } + }, "expression": { "type": "Identifier", "start": 50, @@ -119,4 +131,4 @@ "sourceType": "module" } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/comment-with-ignores/output.json b/packages/svelte/tests/parser-legacy/samples/comment-with-ignores/output.json index 74d0a5270773..2caf252de8c3 100644 --- a/packages/svelte/tests/parser-legacy/samples/comment-with-ignores/output.json +++ b/packages/svelte/tests/parser-legacy/samples/comment-with-ignores/output.json @@ -16,4 +16,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/comment/output.json b/packages/svelte/tests/parser-legacy/samples/comment/output.json index a721ddd8dc5b..6017db404cb9 100644 --- a/packages/svelte/tests/parser-legacy/samples/comment/output.json +++ b/packages/svelte/tests/parser-legacy/samples/comment/output.json @@ -13,4 +13,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/component-dynamic/output.json b/packages/svelte/tests/parser-legacy/samples/component-dynamic/output.json index 7e7267498fdc..f624a04c617b 100644 --- a/packages/svelte/tests/parser-legacy/samples/component-dynamic/output.json +++ b/packages/svelte/tests/parser-legacy/samples/component-dynamic/output.json @@ -77,4 +77,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/convert-entities-in-element/output.json b/packages/svelte/tests/parser-legacy/samples/convert-entities-in-element/output.json index 3025f2c8007e..f7a8a3c67794 100644 --- a/packages/svelte/tests/parser-legacy/samples/convert-entities-in-element/output.json +++ b/packages/svelte/tests/parser-legacy/samples/convert-entities-in-element/output.json @@ -22,4 +22,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/convert-entities/output.json b/packages/svelte/tests/parser-legacy/samples/convert-entities/output.json index c43621cc6bb8..c336a3978c30 100644 --- a/packages/svelte/tests/parser-legacy/samples/convert-entities/output.json +++ b/packages/svelte/tests/parser-legacy/samples/convert-entities/output.json @@ -13,4 +13,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/css/output.json b/packages/svelte/tests/parser-legacy/samples/css/output.json index 443d6d2d5000..b3ecd7b6712a 100644 --- a/packages/svelte/tests/parser-legacy/samples/css/output.json +++ b/packages/svelte/tests/parser-legacy/samples/css/output.json @@ -82,4 +82,4 @@ "comment": null } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/dynamic-element-string/output.json b/packages/svelte/tests/parser-legacy/samples/dynamic-element-string/output.json index 5f73e70b5ee7..4768501c46dd 100644 --- a/packages/svelte/tests/parser-legacy/samples/dynamic-element-string/output.json +++ b/packages/svelte/tests/parser-legacy/samples/dynamic-element-string/output.json @@ -156,6 +156,18 @@ "start": 263, "end": 274, "name": "class", + "name_loc": { + "start": { + "line": 7, + "column": 29, + "character": 263 + }, + "end": { + "line": 7, + "column": 34, + "character": 268 + } + }, "value": [ { "start": 270, @@ -171,4 +183,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/dynamic-element-variable/output.json b/packages/svelte/tests/parser-legacy/samples/dynamic-element-variable/output.json index 7c75c8bc2a5f..6d9a5c78ee28 100644 --- a/packages/svelte/tests/parser-legacy/samples/dynamic-element-variable/output.json +++ b/packages/svelte/tests/parser-legacy/samples/dynamic-element-variable/output.json @@ -62,6 +62,18 @@ "start": 72, "end": 83, "name": "class", + "name_loc": { + "start": { + "line": 2, + "column": 27, + "character": 72 + }, + "end": { + "line": 2, + "column": 32, + "character": 77 + } + }, "value": [ { "start": 79, @@ -77,4 +89,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/dynamic-import/output.json b/packages/svelte/tests/parser-legacy/samples/dynamic-import/output.json index 943376010ca1..ee19d5874222 100644 --- a/packages/svelte/tests/parser-legacy/samples/dynamic-import/output.json +++ b/packages/svelte/tests/parser-legacy/samples/dynamic-import/output.json @@ -481,4 +481,4 @@ "sourceType": "module" } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/each-block-destructured/output.json b/packages/svelte/tests/parser-legacy/samples/each-block-destructured/output.json index 21b059b7ae08..637da24aea98 100644 --- a/packages/svelte/tests/parser-legacy/samples/each-block-destructured/output.json +++ b/packages/svelte/tests/parser-legacy/samples/each-block-destructured/output.json @@ -266,4 +266,4 @@ "sourceType": "module" } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/each-block-else/output.json b/packages/svelte/tests/parser-legacy/samples/each-block-else/output.json index f5145063e44c..c8458f96f0a5 100644 --- a/packages/svelte/tests/parser-legacy/samples/each-block-else/output.json +++ b/packages/svelte/tests/parser-legacy/samples/each-block-else/output.json @@ -44,6 +44,7 @@ "type": "Identifier", "name": "animal", "start": 18, + "end": 24, "loc": { "start": { "line": 1, @@ -55,8 +56,7 @@ "column": 24, "character": 24 } - }, - "end": 24 + } }, "expression": { "type": "Identifier", @@ -100,4 +100,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/each-block-indexed/output.json b/packages/svelte/tests/parser-legacy/samples/each-block-indexed/output.json index ce2f921d86ac..2ba41d56b890 100644 --- a/packages/svelte/tests/parser-legacy/samples/each-block-indexed/output.json +++ b/packages/svelte/tests/parser-legacy/samples/each-block-indexed/output.json @@ -72,6 +72,7 @@ "type": "Identifier", "name": "animal", "start": 18, + "end": 24, "loc": { "start": { "line": 1, @@ -83,8 +84,7 @@ "column": 24, "character": 24 } - }, - "end": 24 + } }, "expression": { "type": "Identifier", @@ -106,4 +106,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/each-block-keyed/output.json b/packages/svelte/tests/parser-legacy/samples/each-block-keyed/output.json index 637dab61b897..569681506b89 100644 --- a/packages/svelte/tests/parser-legacy/samples/each-block-keyed/output.json +++ b/packages/svelte/tests/parser-legacy/samples/each-block-keyed/output.json @@ -44,6 +44,7 @@ "type": "Identifier", "name": "todo", "start": 16, + "end": 20, "loc": { "start": { "line": 1, @@ -55,8 +56,7 @@ "column": 20, "character": 20 } - }, - "end": 20 + } }, "expression": { "type": "Identifier", @@ -126,4 +126,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/each-block/output.json b/packages/svelte/tests/parser-legacy/samples/each-block/output.json index 82390bb62874..c763dc6b8576 100644 --- a/packages/svelte/tests/parser-legacy/samples/each-block/output.json +++ b/packages/svelte/tests/parser-legacy/samples/each-block/output.json @@ -44,6 +44,7 @@ "type": "Identifier", "name": "animal", "start": 18, + "end": 24, "loc": { "start": { "line": 1, @@ -55,8 +56,7 @@ "column": 24, "character": 24 } - }, - "end": 24 + } }, "expression": { "type": "Identifier", @@ -77,4 +77,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/element-with-attribute-empty-string/output.json b/packages/svelte/tests/parser-legacy/samples/element-with-attribute-empty-string/output.json index afdcbf4297cf..2d6a4b752c90 100644 --- a/packages/svelte/tests/parser-legacy/samples/element-with-attribute-empty-string/output.json +++ b/packages/svelte/tests/parser-legacy/samples/element-with-attribute-empty-string/output.json @@ -15,6 +15,18 @@ "start": 6, "end": 13, "name": "attr", + "name_loc": { + "start": { + "line": 1, + "column": 6, + "character": 6 + }, + "end": { + "line": 1, + "column": 10, + "character": 10 + } + }, "value": [ { "start": 12, @@ -46,6 +58,18 @@ "start": 28, "end": 35, "name": "attr", + "name_loc": { + "start": { + "line": 2, + "column": 6, + "character": 28 + }, + "end": { + "line": 2, + "column": 10, + "character": 32 + } + }, "value": [ { "start": 34, @@ -61,4 +85,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/element-with-attribute/output.json b/packages/svelte/tests/parser-legacy/samples/element-with-attribute/output.json index b6740a61357c..9fdb601b67fc 100644 --- a/packages/svelte/tests/parser-legacy/samples/element-with-attribute/output.json +++ b/packages/svelte/tests/parser-legacy/samples/element-with-attribute/output.json @@ -15,6 +15,18 @@ "start": 6, "end": 16, "name": "attr", + "name_loc": { + "start": { + "line": 1, + "column": 6, + "character": 6 + }, + "end": { + "line": 1, + "column": 10, + "character": 10 + } + }, "value": [ { "start": 12, @@ -46,6 +58,18 @@ "start": 31, "end": 41, "name": "attr", + "name_loc": { + "start": { + "line": 2, + "column": 6, + "character": 31 + }, + "end": { + "line": 2, + "column": 10, + "character": 35 + } + }, "value": [ { "start": 37, @@ -61,4 +85,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/element-with-mustache/output.json b/packages/svelte/tests/parser-legacy/samples/element-with-mustache/output.json index 9bb92244ce68..ce0dc25e85c6 100644 --- a/packages/svelte/tests/parser-legacy/samples/element-with-mustache/output.json +++ b/packages/svelte/tests/parser-legacy/samples/element-with-mustache/output.json @@ -50,4 +50,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/element-with-text/output.json b/packages/svelte/tests/parser-legacy/samples/element-with-text/output.json index d8bb9e9c1185..fde57c470a64 100644 --- a/packages/svelte/tests/parser-legacy/samples/element-with-text/output.json +++ b/packages/svelte/tests/parser-legacy/samples/element-with-text/output.json @@ -22,4 +22,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/elements/output.json b/packages/svelte/tests/parser-legacy/samples/elements/output.json index 97513445d695..afc49c56c332 100644 --- a/packages/svelte/tests/parser-legacy/samples/elements/output.json +++ b/packages/svelte/tests/parser-legacy/samples/elements/output.json @@ -15,6 +15,18 @@ "start": 10, "end": 14, "name": "html", + "name_loc": { + "start": { + "line": 1, + "column": 10, + "character": 10 + }, + "end": { + "line": 1, + "column": 14, + "character": 14 + } + }, "value": true } ], @@ -22,4 +34,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/event-handler/output.json b/packages/svelte/tests/parser-legacy/samples/event-handler/output.json index 218b349628a7..8b054a4289f8 100644 --- a/packages/svelte/tests/parser-legacy/samples/event-handler/output.json +++ b/packages/svelte/tests/parser-legacy/samples/event-handler/output.json @@ -15,6 +15,18 @@ "end": 45, "type": "EventHandler", "name": "click", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 16, + "character": 16 + } + }, "expression": { "type": "ArrowFunctionExpression", "start": 19, @@ -161,4 +173,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/generic-snippets/output.json b/packages/svelte/tests/parser-legacy/samples/generic-snippets/output.json index 72672cafbc95..9cb5d765e875 100644 --- a/packages/svelte/tests/parser-legacy/samples/generic-snippets/output.json +++ b/packages/svelte/tests/parser-legacy/samples/generic-snippets/output.json @@ -17,9 +17,21 @@ "end": 92, "expression": { "type": "Identifier", + "name": "generic", "start": 40, "end": 47, - "name": "generic" + "loc": { + "start": { + "line": 4, + "column": 10, + "character": 40 + }, + "end": { + "line": 4, + "column": 17, + "character": 47 + } + } }, "parameters": [ { @@ -123,9 +135,21 @@ "end": 192, "expression": { "type": "Identifier", + "name": "complex_generic", "start": 104, "end": 119, - "name": "complex_generic" + "loc": { + "start": { + "line": 8, + "column": 10, + "character": 104 + }, + "end": { + "line": 8, + "column": 25, + "character": 119 + } + } }, "parameters": [ { @@ -241,4 +265,4 @@ "sourceType": "module" } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/if-block-else/output.json b/packages/svelte/tests/parser-legacy/samples/if-block-else/output.json index 34efb9fd7b22..4ba9370d8870 100644 --- a/packages/svelte/tests/parser-legacy/samples/if-block-else/output.json +++ b/packages/svelte/tests/parser-legacy/samples/if-block-else/output.json @@ -68,4 +68,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/if-block-elseif/output.json b/packages/svelte/tests/parser-legacy/samples/if-block-elseif/output.json index d246cd117900..f2af3d5a4b92 100644 --- a/packages/svelte/tests/parser-legacy/samples/if-block-elseif/output.json +++ b/packages/svelte/tests/parser-legacy/samples/if-block-elseif/output.json @@ -221,4 +221,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/if-block/output.json b/packages/svelte/tests/parser-legacy/samples/if-block/output.json index 1c60df0d31c8..61ecf6e3b2b4 100644 --- a/packages/svelte/tests/parser-legacy/samples/if-block/output.json +++ b/packages/svelte/tests/parser-legacy/samples/if-block/output.json @@ -36,4 +36,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/implicitly-closed-li/output.json b/packages/svelte/tests/parser-legacy/samples/implicitly-closed-li/output.json index be5fba538e42..a56701894e63 100644 --- a/packages/svelte/tests/parser-legacy/samples/implicitly-closed-li/output.json +++ b/packages/svelte/tests/parser-legacy/samples/implicitly-closed-li/output.json @@ -70,4 +70,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/javascript-comments/output.json b/packages/svelte/tests/parser-legacy/samples/javascript-comments/output.json index a5fe5749da34..4723564f174d 100644 --- a/packages/svelte/tests/parser-legacy/samples/javascript-comments/output.json +++ b/packages/svelte/tests/parser-legacy/samples/javascript-comments/output.json @@ -22,6 +22,18 @@ "end": 692, "type": "EventHandler", "name": "click", + "name_loc": { + "start": { + "line": 34, + "column": 1, + "character": 574 + }, + "end": { + "line": 34, + "column": 9, + "character": 582 + } + }, "expression": { "type": "ArrowFunctionExpression", "start": 596, @@ -869,4 +881,4 @@ "sourceType": "module" } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/loose-invalid-block/output.json b/packages/svelte/tests/parser-legacy/samples/loose-invalid-block/output.json index c8f248ee6c2c..c4d0dd4aa470 100644 --- a/packages/svelte/tests/parser-legacy/samples/loose-invalid-block/output.json +++ b/packages/svelte/tests/parser-legacy/samples/loose-invalid-block/output.json @@ -75,9 +75,21 @@ "end": 75, "expression": { "type": "Identifier", + "name": "", "start": 63, "end": 63, - "name": "" + "loc": { + "start": { + "line": 9, + "column": 10, + "character": 63 + }, + "end": { + "line": 9, + "column": 10, + "character": 63 + } + } }, "parameters": [], "children": [] @@ -95,13 +107,25 @@ "end": 102, "expression": { "type": "Identifier", + "name": "foo", "start": 87, "end": 90, - "name": "foo" + "loc": { + "start": { + "line": 12, + "column": 10, + "character": 87 + }, + "end": { + "line": 12, + "column": 13, + "character": 90 + } + } }, "parameters": [], "children": [] } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/loose-invalid-expression/output.json b/packages/svelte/tests/parser-legacy/samples/loose-invalid-expression/output.json index b04a37e5e9d6..136c45fc6e52 100644 --- a/packages/svelte/tests/parser-legacy/samples/loose-invalid-expression/output.json +++ b/packages/svelte/tests/parser-legacy/samples/loose-invalid-expression/output.json @@ -15,16 +15,40 @@ "start": 5, "end": 7, "name": "", + "name_loc": { + "start": { + "line": 1, + "column": 6, + "character": 6 + }, + "end": { + "line": 1, + "column": 6, + "character": 6 + } + }, "value": [ { "type": "AttributeShorthand", "start": 6, "end": 6, "expression": { + "type": "Identifier", + "name": "", "start": 6, "end": 6, - "type": "Identifier", - "name": "" + "loc": { + "start": { + "line": 1, + "column": 6, + "character": 6 + }, + "end": { + "line": 1, + "column": 6, + "character": 6 + } + } } } ] @@ -50,6 +74,18 @@ "start": 20, "end": 26, "name": "foo", + "name_loc": { + "start": { + "line": 2, + "column": 5, + "character": 20 + }, + "end": { + "line": 2, + "column": 8, + "character": 23 + } + }, "value": [ { "type": "MustacheTag", @@ -85,6 +121,18 @@ "start": 40, "end": 48, "name": "foo", + "name_loc": { + "start": { + "line": 4, + "column": 5, + "character": 40 + }, + "end": { + "line": 4, + "column": 8, + "character": 43 + } + }, "value": [ { "type": "MustacheTag", @@ -120,6 +168,18 @@ "start": 61, "end": 73, "name": "foo", + "name_loc": { + "start": { + "line": 5, + "column": 5, + "character": 61 + }, + "end": { + "line": 5, + "column": 8, + "character": 64 + } + }, "value": [ { "type": "MustacheTag", @@ -155,6 +215,18 @@ "start": 92, "end": 110, "name": "onclick", + "name_loc": { + "start": { + "line": 6, + "column": 11, + "character": 92 + }, + "end": { + "line": 6, + "column": 18, + "character": 99 + } + }, "value": [ { "type": "MustacheTag", @@ -190,6 +262,18 @@ "end": 137, "type": "Binding", "name": "value", + "name_loc": { + "start": { + "line": 8, + "column": 7, + "character": 122 + }, + "end": { + "line": 8, + "column": 17, + "character": 132 + } + }, "expression": { "type": "Identifier", "start": 134, @@ -272,6 +356,7 @@ "type": "Identifier", "name": "item", "start": 197, + "end": 201, "loc": { "start": { "line": 15, @@ -283,8 +368,7 @@ "column": 20, "character": 201 } - }, - "end": 201 + } }, "expression": { "type": "Identifier", @@ -325,6 +409,7 @@ "type": "Identifier", "name": "item", "start": 234, + "end": 238, "loc": { "start": { "line": 17, @@ -336,8 +421,7 @@ "column": 19, "character": 238 } - }, - "end": 238 + } }, "expression": { "type": "Identifier", @@ -408,6 +492,7 @@ "type": "Identifier", "name": "y", "start": 285, + "end": 286, "loc": { "start": { "line": 21, @@ -419,8 +504,7 @@ "column": 17, "character": 286 } - }, - "end": 286 + } }, "error": null, "pending": { @@ -467,6 +551,7 @@ "type": "Identifier", "name": "y", "start": 314, + "end": 315, "loc": { "start": { "line": 23, @@ -478,8 +563,7 @@ "column": 18, "character": 315 } - }, - "end": 315 + } }, "pending": { "type": "PendingBlock", @@ -505,4 +589,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/loose-unclosed-block/output.json b/packages/svelte/tests/parser-legacy/samples/loose-unclosed-block/output.json index ee4efc2a9c7f..37a46a48da4f 100644 --- a/packages/svelte/tests/parser-legacy/samples/loose-unclosed-block/output.json +++ b/packages/svelte/tests/parser-legacy/samples/loose-unclosed-block/output.json @@ -240,6 +240,7 @@ "type": "Identifier", "name": "y", "start": 138, + "end": 139, "loc": { "start": { "line": 19, @@ -251,8 +252,7 @@ "column": 13, "character": 139 } - }, - "end": 139 + } }, "expression": { "type": "Identifier", @@ -273,4 +273,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/loose-unclosed-open-tag/output.json b/packages/svelte/tests/parser-legacy/samples/loose-unclosed-open-tag/output.json index 1002df6b67c0..9d5d0e7658d3 100644 --- a/packages/svelte/tests/parser-legacy/samples/loose-unclosed-open-tag/output.json +++ b/packages/svelte/tests/parser-legacy/samples/loose-unclosed-open-tag/output.json @@ -29,6 +29,18 @@ "start": 13, "end": 22, "name": "foo", + "name_loc": { + "start": { + "line": 2, + "column": 7, + "character": 13 + }, + "end": { + "line": 2, + "column": 10, + "character": 16 + } + }, "value": [ { "type": "MustacheTag", @@ -90,6 +102,18 @@ "start": 44, "end": 53, "name": "foo", + "name_loc": { + "start": { + "line": 6, + "column": 7, + "character": 44 + }, + "end": { + "line": 6, + "column": 10, + "character": 47 + } + }, "value": [ { "type": "MustacheTag", @@ -158,6 +182,18 @@ "start": 79, "end": 88, "name": "foo", + "name_loc": { + "start": { + "line": 10, + "column": 7, + "character": 79 + }, + "end": { + "line": 10, + "column": 10, + "character": 82 + } + }, "value": [ { "type": "MustacheTag", @@ -226,6 +262,18 @@ "start": 113, "end": 122, "name": "foo", + "name_loc": { + "start": { + "line": 14, + "column": 7, + "character": 113 + }, + "end": { + "line": 14, + "column": 10, + "character": 116 + } + }, "value": [ { "type": "MustacheTag", @@ -317,6 +365,18 @@ "start": 161, "end": 170, "name": "foo", + "name_loc": { + "start": { + "line": 20, + "column": 5, + "character": 161 + }, + "end": { + "line": 20, + "column": 8, + "character": 164 + } + }, "value": [ { "type": "MustacheTag", @@ -346,4 +406,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/loose-unclosed-tag/output.json b/packages/svelte/tests/parser-legacy/samples/loose-unclosed-tag/output.json index 4b6d31902f8f..1ff3342de08d 100644 --- a/packages/svelte/tests/parser-legacy/samples/loose-unclosed-tag/output.json +++ b/packages/svelte/tests/parser-legacy/samples/loose-unclosed-tag/output.json @@ -68,6 +68,18 @@ "start": 35, "end": 44, "name": "foo", + "name_loc": { + "start": { + "line": 6, + "column": 7, + "character": 35 + }, + "end": { + "line": 6, + "column": 10, + "character": 38 + } + }, "value": [ { "type": "MustacheTag", @@ -275,6 +287,18 @@ "start": 159, "end": 168, "name": "foo", + "name_loc": { + "start": { + "line": 26, + "column": 7, + "character": 159 + }, + "end": { + "line": 26, + "column": 10, + "character": 162 + } + }, "value": [ { "type": "MustacheTag", @@ -360,4 +384,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/nbsp/output.json b/packages/svelte/tests/parser-legacy/samples/nbsp/output.json index a120b08f327a..7d2158955a64 100644 --- a/packages/svelte/tests/parser-legacy/samples/nbsp/output.json +++ b/packages/svelte/tests/parser-legacy/samples/nbsp/output.json @@ -22,4 +22,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/no-error-if-before-closing/output.json b/packages/svelte/tests/parser-legacy/samples/no-error-if-before-closing/output.json index 369cd4acc4bf..de12cffd86ae 100644 --- a/packages/svelte/tests/parser-legacy/samples/no-error-if-before-closing/output.json +++ b/packages/svelte/tests/parser-legacy/samples/no-error-if-before-closing/output.json @@ -119,6 +119,7 @@ "type": "Identifier", "name": "f", "start": 97, + "end": 98, "loc": { "start": { "line": 13, @@ -130,8 +131,7 @@ "column": 8, "character": 98 } - }, - "end": 98 + } }, "error": null, "pending": { @@ -219,6 +219,7 @@ "type": "Identifier", "name": "f", "start": 137, + "end": 138, "loc": { "start": { "line": 18, @@ -230,8 +231,7 @@ "column": 8, "character": 138 } - }, - "end": 138 + } }, "error": null, "pending": { @@ -289,4 +289,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/raw-mustaches/output.json b/packages/svelte/tests/parser-legacy/samples/raw-mustaches/output.json index b8e1da749937..7db0bb7ec15a 100644 --- a/packages/svelte/tests/parser-legacy/samples/raw-mustaches/output.json +++ b/packages/svelte/tests/parser-legacy/samples/raw-mustaches/output.json @@ -78,4 +78,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/refs/output.json b/packages/svelte/tests/parser-legacy/samples/refs/output.json index 108fa78697c4..7f30946fc58b 100644 --- a/packages/svelte/tests/parser-legacy/samples/refs/output.json +++ b/packages/svelte/tests/parser-legacy/samples/refs/output.json @@ -22,6 +22,18 @@ "end": 53, "type": "Binding", "name": "this", + "name_loc": { + "start": { + "line": 5, + "column": 8, + "character": 38 + }, + "end": { + "line": 5, + "column": 17, + "character": 47 + } + }, "expression": { "type": "Identifier", "start": 49, @@ -119,4 +131,4 @@ "sourceType": "module" } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/script-attribute-with-curly-braces/output.json b/packages/svelte/tests/parser-legacy/samples/script-attribute-with-curly-braces/output.json index e9298ec50c24..e0b50e3b92db 100644 --- a/packages/svelte/tests/parser-legacy/samples/script-attribute-with-curly-braces/output.json +++ b/packages/svelte/tests/parser-legacy/samples/script-attribute-with-curly-braces/output.json @@ -147,4 +147,4 @@ "sourceType": "module" } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/script-comment-only/output.json b/packages/svelte/tests/parser-legacy/samples/script-comment-only/output.json index 502d5df57600..b04a823e8db6 100644 --- a/packages/svelte/tests/parser-legacy/samples/script-comment-only/output.json +++ b/packages/svelte/tests/parser-legacy/samples/script-comment-only/output.json @@ -52,4 +52,4 @@ ] } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/script-context-module-unquoted/output.json b/packages/svelte/tests/parser-legacy/samples/script-context-module-unquoted/output.json index 5a380a32404a..64250cb302e4 100644 --- a/packages/svelte/tests/parser-legacy/samples/script-context-module-unquoted/output.json +++ b/packages/svelte/tests/parser-legacy/samples/script-context-module-unquoted/output.json @@ -176,4 +176,4 @@ "sourceType": "module" } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/script/output.json b/packages/svelte/tests/parser-legacy/samples/script/output.json index e30414a2a839..d3d4abd6b24f 100644 --- a/packages/svelte/tests/parser-legacy/samples/script/output.json +++ b/packages/svelte/tests/parser-legacy/samples/script/output.json @@ -147,4 +147,4 @@ "sourceType": "module" } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/self-closing-element/output.json b/packages/svelte/tests/parser-legacy/samples/self-closing-element/output.json index fe59cac4b760..f0ba3a5c0d7a 100644 --- a/packages/svelte/tests/parser-legacy/samples/self-closing-element/output.json +++ b/packages/svelte/tests/parser-legacy/samples/self-closing-element/output.json @@ -14,4 +14,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/self-reference/output.json b/packages/svelte/tests/parser-legacy/samples/self-reference/output.json index 44547698fd3c..1ca684931b6e 100644 --- a/packages/svelte/tests/parser-legacy/samples/self-reference/output.json +++ b/packages/svelte/tests/parser-legacy/samples/self-reference/output.json @@ -69,6 +69,18 @@ "start": 30, "end": 49, "name": "depth", + "name_loc": { + "start": { + "line": 2, + "column": 14, + "character": 30 + }, + "end": { + "line": 2, + "column": 19, + "character": 35 + } + }, "value": [ { "type": "MustacheTag", @@ -133,4 +145,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/slotted-element/output.json b/packages/svelte/tests/parser-legacy/samples/slotted-element/output.json index c6717f3074bd..caa0b86c4546 100644 --- a/packages/svelte/tests/parser-legacy/samples/slotted-element/output.json +++ b/packages/svelte/tests/parser-legacy/samples/slotted-element/output.json @@ -22,6 +22,18 @@ "start": 16, "end": 26, "name": "slot", + "name_loc": { + "start": { + "line": 1, + "column": 16, + "character": 16 + }, + "end": { + "line": 1, + "column": 20, + "character": 20 + } + }, "value": [ { "start": 22, @@ -39,4 +51,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/space-between-mustaches/output.json b/packages/svelte/tests/parser-legacy/samples/space-between-mustaches/output.json index 7553651864cc..bb6de0bea951 100644 --- a/packages/svelte/tests/parser-legacy/samples/space-between-mustaches/output.json +++ b/packages/svelte/tests/parser-legacy/samples/space-between-mustaches/output.json @@ -106,4 +106,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/spread/output.json b/packages/svelte/tests/parser-legacy/samples/spread/output.json index b1d80bd5d418..3b79aa967028 100644 --- a/packages/svelte/tests/parser-legacy/samples/spread/output.json +++ b/packages/svelte/tests/parser-legacy/samples/spread/output.json @@ -36,4 +36,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/style-inside-head/output.json b/packages/svelte/tests/parser-legacy/samples/style-inside-head/output.json index 25588b950b83..733f9e76fff4 100644 --- a/packages/svelte/tests/parser-legacy/samples/style-inside-head/output.json +++ b/packages/svelte/tests/parser-legacy/samples/style-inside-head/output.json @@ -30,4 +30,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/textarea-children/output.json b/packages/svelte/tests/parser-legacy/samples/textarea-children/output.json index 62a295c1352b..60477807b79c 100644 --- a/packages/svelte/tests/parser-legacy/samples/textarea-children/output.json +++ b/packages/svelte/tests/parser-legacy/samples/textarea-children/output.json @@ -50,4 +50,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/textarea-end-tag/output.json b/packages/svelte/tests/parser-legacy/samples/textarea-end-tag/output.json index 145de96560cf..ed3c85b09a07 100644 --- a/packages/svelte/tests/parser-legacy/samples/textarea-end-tag/output.json +++ b/packages/svelte/tests/parser-legacy/samples/textarea-end-tag/output.json @@ -50,4 +50,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/transition-intro-no-params/output.json b/packages/svelte/tests/parser-legacy/samples/transition-intro-no-params/output.json index 85f45a93f51b..9f0d007cc85f 100644 --- a/packages/svelte/tests/parser-legacy/samples/transition-intro-no-params/output.json +++ b/packages/svelte/tests/parser-legacy/samples/transition-intro-no-params/output.json @@ -15,6 +15,18 @@ "end": 12, "type": "Transition", "name": "fade", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, "expression": null, "modifiers": [], "intro": true, @@ -33,4 +45,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/transition-intro/output.json b/packages/svelte/tests/parser-legacy/samples/transition-intro/output.json index be201143b45a..61b4afbc133f 100644 --- a/packages/svelte/tests/parser-legacy/samples/transition-intro/output.json +++ b/packages/svelte/tests/parser-legacy/samples/transition-intro/output.json @@ -15,6 +15,18 @@ "end": 30, "type": "Transition", "name": "style", + "name_loc": { + "start": { + "line": 1, + "column": 5, + "character": 5 + }, + "end": { + "line": 1, + "column": 13, + "character": 13 + } + }, "expression": { "type": "ObjectExpression", "start": 16, @@ -101,4 +113,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/unusual-identifier/output.json b/packages/svelte/tests/parser-legacy/samples/unusual-identifier/output.json index b1595a6839a4..da5555a7776d 100644 --- a/packages/svelte/tests/parser-legacy/samples/unusual-identifier/output.json +++ b/packages/svelte/tests/parser-legacy/samples/unusual-identifier/output.json @@ -44,6 +44,7 @@ "type": "Identifier", "name": "𐊧", "start": 17, + "end": 19, "loc": { "start": { "line": 1, @@ -55,8 +56,7 @@ "column": 19, "character": 19 } - }, - "end": 19 + } }, "expression": { "type": "Identifier", @@ -77,4 +77,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/whitespace-after-script-tag/output.json b/packages/svelte/tests/parser-legacy/samples/whitespace-after-script-tag/output.json index dee3ba5f2999..69b23824423d 100644 --- a/packages/svelte/tests/parser-legacy/samples/whitespace-after-script-tag/output.json +++ b/packages/svelte/tests/parser-legacy/samples/whitespace-after-script-tag/output.json @@ -147,4 +147,4 @@ "sourceType": "module" } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/whitespace-after-style-tag/output.json b/packages/svelte/tests/parser-legacy/samples/whitespace-after-style-tag/output.json index acd9798425f2..2cadbc672f9d 100644 --- a/packages/svelte/tests/parser-legacy/samples/whitespace-after-style-tag/output.json +++ b/packages/svelte/tests/parser-legacy/samples/whitespace-after-style-tag/output.json @@ -82,4 +82,4 @@ "comment": null } } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/whitespace-leading-trailing/output.json b/packages/svelte/tests/parser-legacy/samples/whitespace-leading-trailing/output.json index 67ffc034368e..baffebfed7f6 100644 --- a/packages/svelte/tests/parser-legacy/samples/whitespace-leading-trailing/output.json +++ b/packages/svelte/tests/parser-legacy/samples/whitespace-leading-trailing/output.json @@ -29,4 +29,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/samples/whitespace-normal/output.json b/packages/svelte/tests/parser-legacy/samples/whitespace-normal/output.json index 27f8e537a157..4fb88b818d83 100644 --- a/packages/svelte/tests/parser-legacy/samples/whitespace-normal/output.json +++ b/packages/svelte/tests/parser-legacy/samples/whitespace-normal/output.json @@ -75,4 +75,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-legacy/test.ts b/packages/svelte/tests/parser-legacy/test.ts index 987253d8d069..2e64389404fe 100644 --- a/packages/svelte/tests/parser-legacy/test.ts +++ b/packages/svelte/tests/parser-legacy/test.ts @@ -18,7 +18,7 @@ const { test, run } = suite(async (config, cwd) => { // run `UPDATE_SNAPSHOTS=true pnpm test parser` to update parser tests if (process.env.UPDATE_SNAPSHOTS) { - fs.writeFileSync(`${cwd}/output.json`, JSON.stringify(actual, null, '\t')); + fs.writeFileSync(`${cwd}/output.json`, JSON.stringify(actual, null, '\t') + '\n'); } else { fs.writeFileSync(`${cwd}/_actual.json`, JSON.stringify(actual, null, '\t')); diff --git a/packages/svelte/tests/parser-modern/samples/attachments/output.json b/packages/svelte/tests/parser-modern/samples/attachments/output.json index 56dd077add5e..d37fec7beb75 100644 --- a/packages/svelte/tests/parser-modern/samples/attachments/output.json +++ b/packages/svelte/tests/parser-modern/samples/attachments/output.json @@ -12,6 +12,18 @@ "start": 0, "end": 57, "name": "div", + "name_loc": { + "start": { + "line": 1, + "column": 1, + "character": 1 + }, + "end": { + "line": 1, + "column": 4, + "character": 4 + } + }, "attributes": [ { "type": "AttachTag", @@ -138,4 +150,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/comment-before-function-binding/output.json b/packages/svelte/tests/parser-modern/samples/comment-before-function-binding/output.json index 7189e27e964d..b26ee2866fcc 100644 --- a/packages/svelte/tests/parser-modern/samples/comment-before-function-binding/output.json +++ b/packages/svelte/tests/parser-modern/samples/comment-before-function-binding/output.json @@ -19,12 +19,36 @@ "start": 37, "end": 117, "name": "input", + "name_loc": { + "start": { + "line": 5, + "column": 1, + "character": 38 + }, + "end": { + "line": 5, + "column": 6, + "character": 43 + } + }, "attributes": [ { "start": 44, "end": 114, "type": "BindDirective", "name": "value", + "name_loc": { + "start": { + "line": 5, + "column": 7, + "character": 44 + }, + "end": { + "line": 5, + "column": 17, + "character": 54 + } + }, "expression": { "type": "SequenceExpression", "start": 68, @@ -323,4 +347,4 @@ }, "attributes": [] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/comment-before-script/output.json b/packages/svelte/tests/parser-modern/samples/comment-before-script/output.json index 39bfd4323770..827ad85d92f8 100644 --- a/packages/svelte/tests/parser-modern/samples/comment-before-script/output.json +++ b/packages/svelte/tests/parser-modern/samples/comment-before-script/output.json @@ -138,6 +138,18 @@ "start": 36, "end": 45, "name": "lang", + "name_loc": { + "start": { + "line": 2, + "column": 8, + "character": 36 + }, + "end": { + "line": 2, + "column": 12, + "character": 40 + } + }, "value": [ { "start": 42, @@ -150,4 +162,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json b/packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json index a4abf172ac89..26b4998587da 100644 --- a/packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json +++ b/packages/svelte/tests/parser-modern/samples/css-nth-syntax/output.json @@ -1097,6 +1097,18 @@ "start": 808, "end": 820, "name": "h1", + "name_loc": { + "start": { + "line": 46, + "column": 1, + "character": 809 + }, + "end": { + "line": 46, + "column": 3, + "character": 811 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -1114,4 +1126,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/css-pseudo-classes/output.json b/packages/svelte/tests/parser-modern/samples/css-pseudo-classes/output.json index a2e0195faba5..e410cf2a801b 100644 --- a/packages/svelte/tests/parser-modern/samples/css-pseudo-classes/output.json +++ b/packages/svelte/tests/parser-modern/samples/css-pseudo-classes/output.json @@ -406,4 +406,4 @@ "nodes": [] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/each-block-object-pattern-special-characters/output.json b/packages/svelte/tests/parser-modern/samples/each-block-object-pattern-special-characters/output.json index 37fdf92296ff..7fd5deb3eaed 100644 --- a/packages/svelte/tests/parser-modern/samples/each-block-object-pattern-special-characters/output.json +++ b/packages/svelte/tests/parser-modern/samples/each-block-object-pattern-special-characters/output.json @@ -823,4 +823,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/each-block-object-pattern/output.json b/packages/svelte/tests/parser-modern/samples/each-block-object-pattern/output.json index b2a5f9e0d119..7e2fe09ea2cd 100644 --- a/packages/svelte/tests/parser-modern/samples/each-block-object-pattern/output.json +++ b/packages/svelte/tests/parser-modern/samples/each-block-object-pattern/output.json @@ -42,6 +42,18 @@ "start": 41, "end": 86, "name": "p", + "name_loc": { + "start": { + "line": 2, + "column": 2, + "character": 42 + }, + "end": { + "line": 2, + "column": 3, + "character": 43 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -350,6 +362,18 @@ "start": 155, "end": 200, "name": "p", + "name_loc": { + "start": { + "line": 6, + "column": 2, + "character": 156 + }, + "end": { + "line": 6, + "column": 3, + "character": 157 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -749,6 +773,18 @@ "start": 291, "end": 336, "name": "p", + "name_loc": { + "start": { + "line": 10, + "column": 2, + "character": 292 + }, + "end": { + "line": 10, + "column": 3, + "character": 293 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -1178,4 +1214,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/generic-snippets/output.json b/packages/svelte/tests/parser-modern/samples/generic-snippets/output.json index 44d98b7a9160..5a0e64894ddf 100644 --- a/packages/svelte/tests/parser-modern/samples/generic-snippets/output.json +++ b/packages/svelte/tests/parser-modern/samples/generic-snippets/output.json @@ -20,9 +20,21 @@ "end": 92, "expression": { "type": "Identifier", + "name": "generic", "start": 40, "end": 47, - "name": "generic" + "loc": { + "start": { + "line": 4, + "column": 10, + "character": 40 + }, + "end": { + "line": 4, + "column": 17, + "character": 47 + } + } }, "typeParams": "T extends string", "parameters": [ @@ -143,9 +155,21 @@ "end": 192, "expression": { "type": "Identifier", + "name": "complex_generic", "start": 104, "end": 119, - "name": "complex_generic" + "loc": { + "start": { + "line": 8, + "column": 10, + "character": 104 + }, + "end": { + "line": 8, + "column": 25, + "character": 119 + } + } }, "typeParams": "T extends { bracket: \"<\" } | \"<\" | Set<\"<>\">", "parameters": [ @@ -284,6 +308,18 @@ "start": 8, "end": 17, "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, "value": [ { "start": 14, @@ -296,4 +332,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/if-block-else/output.json b/packages/svelte/tests/parser-modern/samples/if-block-else/output.json index dcccde670cba..13b56db9de0e 100644 --- a/packages/svelte/tests/parser-modern/samples/if-block-else/output.json +++ b/packages/svelte/tests/parser-modern/samples/if-block-else/output.json @@ -43,6 +43,18 @@ "start": 11, "end": 21, "name": "p", + "name_loc": { + "start": { + "line": 2, + "column": 2, + "character": 12 + }, + "end": { + "line": 2, + "column": 3, + "character": 13 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -81,6 +93,18 @@ "start": 31, "end": 45, "name": "p", + "name_loc": { + "start": { + "line": 4, + "column": 2, + "character": 32 + }, + "end": { + "line": 4, + "column": 3, + "character": 33 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -108,4 +132,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/if-block-elseif/output.json b/packages/svelte/tests/parser-modern/samples/if-block-elseif/output.json index 6759f678d871..fb00488f3137 100644 --- a/packages/svelte/tests/parser-modern/samples/if-block-elseif/output.json +++ b/packages/svelte/tests/parser-modern/samples/if-block-elseif/output.json @@ -76,6 +76,18 @@ "start": 14, "end": 41, "name": "p", + "name_loc": { + "start": { + "line": 2, + "column": 2, + "character": 15 + }, + "end": { + "line": 2, + "column": 3, + "character": 16 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -171,6 +183,18 @@ "start": 60, "end": 83, "name": "p", + "name_loc": { + "start": { + "line": 4, + "column": 2, + "character": 61 + }, + "end": { + "line": 4, + "column": 3, + "character": 62 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -202,4 +226,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/if-block/output.json b/packages/svelte/tests/parser-modern/samples/if-block/output.json index 47ad4145a62e..f363ed8274ad 100644 --- a/packages/svelte/tests/parser-modern/samples/if-block/output.json +++ b/packages/svelte/tests/parser-modern/samples/if-block/output.json @@ -45,4 +45,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/loose-invalid-block/output.json b/packages/svelte/tests/parser-modern/samples/loose-invalid-block/output.json index 036b581d0c5d..69fc7a0c81f2 100644 --- a/packages/svelte/tests/parser-modern/samples/loose-invalid-block/output.json +++ b/packages/svelte/tests/parser-modern/samples/loose-invalid-block/output.json @@ -116,9 +116,21 @@ "end": 75, "expression": { "type": "Identifier", + "name": "", "start": 63, "end": 63, - "name": "" + "loc": { + "start": { + "line": 9, + "column": 10, + "character": 63 + }, + "end": { + "line": 9, + "column": 10, + "character": 63 + } + } }, "parameters": [], "body": { @@ -147,9 +159,21 @@ "end": 102, "expression": { "type": "Identifier", + "name": "foo", "start": 87, "end": 90, - "name": "foo" + "loc": { + "start": { + "line": 12, + "column": 10, + "character": 87 + }, + "end": { + "line": 12, + "column": 13, + "character": 90 + } + } }, "parameters": [], "body": { @@ -168,4 +192,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/loose-invalid-expression/output.json b/packages/svelte/tests/parser-modern/samples/loose-invalid-expression/output.json index 6231a1930921..593aebe2791e 100644 --- a/packages/svelte/tests/parser-modern/samples/loose-invalid-expression/output.json +++ b/packages/svelte/tests/parser-modern/samples/loose-invalid-expression/output.json @@ -12,21 +12,57 @@ "start": 0, "end": 14, "name": "div", + "name_loc": { + "start": { + "line": 1, + "column": 1, + "character": 1 + }, + "end": { + "line": 1, + "column": 4, + "character": 4 + } + }, "attributes": [ { "type": "Attribute", "start": 5, "end": 7, "name": "", + "name_loc": { + "start": { + "line": 1, + "column": 6, + "character": 6 + }, + "end": { + "line": 1, + "column": 6, + "character": 6 + } + }, "value": { "type": "ExpressionTag", "start": 6, "end": 6, "expression": { + "type": "Identifier", + "name": "", "start": 6, "end": 6, - "type": "Identifier", - "name": "" + "loc": { + "start": { + "line": 1, + "column": 6, + "character": 6 + }, + "end": { + "line": 1, + "column": 6, + "character": 6 + } + } } } } @@ -48,12 +84,36 @@ "start": 15, "end": 33, "name": "div", + "name_loc": { + "start": { + "line": 2, + "column": 1, + "character": 16 + }, + "end": { + "line": 2, + "column": 4, + "character": 19 + } + }, "attributes": [ { "type": "Attribute", "start": 20, "end": 26, "name": "foo", + "name_loc": { + "start": { + "line": 2, + "column": 5, + "character": 20 + }, + "end": { + "line": 2, + "column": 8, + "character": 23 + } + }, "value": { "type": "ExpressionTag", "start": 24, @@ -84,12 +144,36 @@ "start": 35, "end": 55, "name": "div", + "name_loc": { + "start": { + "line": 4, + "column": 1, + "character": 36 + }, + "end": { + "line": 4, + "column": 4, + "character": 39 + } + }, "attributes": [ { "type": "Attribute", "start": 40, "end": 48, "name": "foo", + "name_loc": { + "start": { + "line": 4, + "column": 5, + "character": 40 + }, + "end": { + "line": 4, + "column": 8, + "character": 43 + } + }, "value": { "type": "ExpressionTag", "start": 44, @@ -120,12 +204,36 @@ "start": 56, "end": 80, "name": "div", + "name_loc": { + "start": { + "line": 5, + "column": 1, + "character": 57 + }, + "end": { + "line": 5, + "column": 4, + "character": 60 + } + }, "attributes": [ { "type": "Attribute", "start": 61, "end": 73, "name": "foo", + "name_loc": { + "start": { + "line": 5, + "column": 5, + "character": 61 + }, + "end": { + "line": 5, + "column": 8, + "character": 64 + } + }, "value": { "type": "ExpressionTag", "start": 65, @@ -156,12 +264,36 @@ "start": 81, "end": 113, "name": "Component", + "name_loc": { + "start": { + "line": 6, + "column": 1, + "character": 82 + }, + "end": { + "line": 6, + "column": 10, + "character": 91 + } + }, "attributes": [ { "type": "Attribute", "start": 92, "end": 110, "name": "onclick", + "name_loc": { + "start": { + "line": 6, + "column": 11, + "character": 92 + }, + "end": { + "line": 6, + "column": 18, + "character": 99 + } + }, "value": { "type": "ExpressionTag", "start": 100, @@ -192,12 +324,36 @@ "start": 115, "end": 140, "name": "input", + "name_loc": { + "start": { + "line": 8, + "column": 1, + "character": 116 + }, + "end": { + "line": 8, + "column": 6, + "character": 121 + } + }, "attributes": [ { "start": 122, "end": 137, "type": "BindDirective", "name": "value", + "name_loc": { + "start": { + "line": 8, + "column": 7, + "character": 122 + }, + "end": { + "line": 8, + "column": 17, + "character": 132 + } + }, "expression": { "type": "Identifier", "start": 134, @@ -307,6 +463,7 @@ "type": "Identifier", "name": "item", "start": 197, + "end": 201, "loc": { "start": { "line": 15, @@ -318,8 +475,7 @@ "column": 20, "character": 201 } - }, - "end": 201 + } }, "key": { "type": "Identifier", @@ -353,6 +509,7 @@ "type": "Identifier", "name": "item", "start": 234, + "end": 238, "loc": { "start": { "line": 17, @@ -364,8 +521,7 @@ "column": 19, "character": 238 } - }, - "end": 238 + } } }, { @@ -415,6 +571,7 @@ "type": "Identifier", "name": "y", "start": 285, + "end": 286, "loc": { "start": { "line": 21, @@ -426,8 +583,7 @@ "column": 17, "character": 286 } - }, - "end": 286 + } }, "error": null, "pending": null, @@ -459,6 +615,7 @@ "type": "Identifier", "name": "y", "start": 314, + "end": 315, "loc": { "start": { "line": 23, @@ -470,8 +627,7 @@ "column": 18, "character": 315 } - }, - "end": 315 + } }, "pending": null, "then": null, @@ -483,4 +639,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/loose-unclosed-open-tag/output.json b/packages/svelte/tests/parser-modern/samples/loose-unclosed-open-tag/output.json index a7985ead8f50..b614e0391dc9 100644 --- a/packages/svelte/tests/parser-modern/samples/loose-unclosed-open-tag/output.json +++ b/packages/svelte/tests/parser-modern/samples/loose-unclosed-open-tag/output.json @@ -12,6 +12,18 @@ "start": 0, "end": 29, "name": "div", + "name_loc": { + "start": { + "line": 1, + "column": 1, + "character": 1 + }, + "end": { + "line": 1, + "column": 4, + "character": 4 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -28,12 +40,36 @@ "start": 7, "end": 23, "name": "Comp", + "name_loc": { + "start": { + "line": 2, + "column": 2, + "character": 8 + }, + "end": { + "line": 2, + "column": 6, + "character": 12 + } + }, "attributes": [ { "type": "Attribute", "start": 13, "end": 22, "name": "foo", + "name_loc": { + "start": { + "line": 2, + "column": 7, + "character": 13 + }, + "end": { + "line": 2, + "column": 10, + "character": 16 + } + }, "value": { "type": "ExpressionTag", "start": 17, @@ -77,6 +113,18 @@ "start": 31, "end": 60, "name": "div", + "name_loc": { + "start": { + "line": 5, + "column": 1, + "character": 32 + }, + "end": { + "line": 5, + "column": 4, + "character": 35 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -93,12 +141,36 @@ "start": 38, "end": 54, "name": "span", + "name_loc": { + "start": { + "line": 6, + "column": 2, + "character": 39 + }, + "end": { + "line": 6, + "column": 6, + "character": 43 + } + }, "attributes": [ { "type": "Attribute", "start": 44, "end": 53, "name": "foo", + "name_loc": { + "start": { + "line": 6, + "column": 7, + "character": 44 + }, + "end": { + "line": 6, + "column": 10, + "character": 47 + } + }, "value": { "type": "ExpressionTag", "start": 48, @@ -173,12 +245,36 @@ "start": 73, "end": 89, "name": "Comp", + "name_loc": { + "start": { + "line": 10, + "column": 2, + "character": 74 + }, + "end": { + "line": 10, + "column": 6, + "character": 78 + } + }, "attributes": [ { "type": "Attribute", "start": 79, "end": 88, "name": "foo", + "name_loc": { + "start": { + "line": 10, + "column": 7, + "character": 79 + }, + "end": { + "line": 10, + "column": 10, + "character": 82 + } + }, "value": { "type": "ExpressionTag", "start": 83, @@ -254,12 +350,36 @@ "start": 107, "end": 124, "name": "Comp", + "name_loc": { + "start": { + "line": 14, + "column": 2, + "character": 108 + }, + "end": { + "line": 14, + "column": 6, + "character": 112 + } + }, "attributes": [ { "type": "Attribute", "start": 113, "end": 122, "name": "foo", + "name_loc": { + "start": { + "line": 14, + "column": 7, + "character": 113 + }, + "end": { + "line": 14, + "column": 10, + "character": 116 + } + }, "value": { "type": "ExpressionTag", "start": 117, @@ -374,12 +494,36 @@ "start": 156, "end": 170, "name": "div", + "name_loc": { + "start": { + "line": 20, + "column": 1, + "character": 157 + }, + "end": { + "line": 20, + "column": 4, + "character": 160 + } + }, "attributes": [ { "type": "Attribute", "start": 161, "end": 170, "name": "foo", + "name_loc": { + "start": { + "line": 20, + "column": 5, + "character": 161 + }, + "end": { + "line": 20, + "column": 8, + "character": 164 + } + }, "value": { "type": "ExpressionTag", "start": 165, @@ -411,4 +555,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/loose-unclosed-tag/output.json b/packages/svelte/tests/parser-modern/samples/loose-unclosed-tag/output.json index df72219d438e..59bff2ff80e0 100644 --- a/packages/svelte/tests/parser-modern/samples/loose-unclosed-tag/output.json +++ b/packages/svelte/tests/parser-modern/samples/loose-unclosed-tag/output.json @@ -12,6 +12,18 @@ "start": 0, "end": 20, "name": "div", + "name_loc": { + "start": { + "line": 1, + "column": 1, + "character": 1 + }, + "end": { + "line": 1, + "column": 4, + "character": 4 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -28,6 +40,18 @@ "start": 7, "end": 14, "name": "Comp", + "name_loc": { + "start": { + "line": 2, + "column": 2, + "character": 8 + }, + "end": { + "line": 2, + "column": 6, + "character": 12 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -57,6 +81,18 @@ "start": 22, "end": 51, "name": "div", + "name_loc": { + "start": { + "line": 5, + "column": 1, + "character": 23 + }, + "end": { + "line": 5, + "column": 4, + "character": 26 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -73,12 +109,36 @@ "start": 29, "end": 45, "name": "Comp", + "name_loc": { + "start": { + "line": 6, + "column": 2, + "character": 30 + }, + "end": { + "line": 6, + "column": 6, + "character": 34 + } + }, "attributes": [ { "type": "Attribute", "start": 35, "end": 44, "name": "foo", + "name_loc": { + "start": { + "line": 6, + "column": 7, + "character": 35 + }, + "end": { + "line": 6, + "column": 10, + "character": 38 + } + }, "value": { "type": "ExpressionTag", "start": 39, @@ -122,6 +182,18 @@ "start": 53, "end": 72, "name": "div", + "name_loc": { + "start": { + "line": 9, + "column": 1, + "character": 54 + }, + "end": { + "line": 9, + "column": 4, + "character": 57 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -138,6 +210,18 @@ "start": 60, "end": 66, "name": "span", + "name_loc": { + "start": { + "line": 10, + "column": 2, + "character": 61 + }, + "end": { + "line": 10, + "column": 6, + "character": 65 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -159,6 +243,18 @@ "start": 74, "end": 94, "name": "div", + "name_loc": { + "start": { + "line": 13, + "column": 1, + "character": 75 + }, + "end": { + "line": 13, + "column": 4, + "character": 78 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -175,6 +271,18 @@ "start": 81, "end": 88, "name": "Comp.", + "name_loc": { + "start": { + "line": 14, + "column": 2, + "character": 82 + }, + "end": { + "line": 14, + "column": 7, + "character": 87 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -196,6 +304,18 @@ "start": 96, "end": 116, "name": "div", + "name_loc": { + "start": { + "line": 17, + "column": 1, + "character": 97 + }, + "end": { + "line": 17, + "column": 4, + "character": 100 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -212,6 +332,18 @@ "start": 103, "end": 110, "name": "comp.", + "name_loc": { + "start": { + "line": 18, + "column": 2, + "character": 104 + }, + "end": { + "line": 18, + "column": 7, + "character": 109 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -264,6 +396,18 @@ "start": 129, "end": 135, "name": "div", + "name_loc": { + "start": { + "line": 22, + "column": 2, + "character": 130 + }, + "end": { + "line": 22, + "column": 5, + "character": 133 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -325,12 +469,36 @@ "start": 153, "end": 169, "name": "Comp", + "name_loc": { + "start": { + "line": 26, + "column": 2, + "character": 154 + }, + "end": { + "line": 26, + "column": 6, + "character": 158 + } + }, "attributes": [ { "type": "Attribute", "start": 159, "end": 168, "name": "foo", + "name_loc": { + "start": { + "line": 26, + "column": 7, + "character": 159 + }, + "end": { + "line": 26, + "column": 10, + "character": 162 + } + }, "value": { "type": "ExpressionTag", "start": 163, @@ -375,6 +543,18 @@ "start": 176, "end": 204, "name": "div", + "name_loc": { + "start": { + "line": 29, + "column": 1, + "character": 177 + }, + "end": { + "line": 29, + "column": 4, + "character": 180 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -391,6 +571,18 @@ "start": 182, "end": 191, "name": "p", + "name_loc": { + "start": { + "line": 30, + "column": 1, + "character": 183 + }, + "end": { + "line": 30, + "column": 2, + "character": 184 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -417,6 +609,18 @@ "start": 193, "end": 204, "name": "open-ended", + "name_loc": { + "start": { + "line": 32, + "column": 1, + "character": 194 + }, + "end": { + "line": 32, + "column": 11, + "character": 204 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -429,4 +633,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/loose-valid-each-as/output.json b/packages/svelte/tests/parser-modern/samples/loose-valid-each-as/output.json index c579e46d6966..6096907d5d9d 100644 --- a/packages/svelte/tests/parser-modern/samples/loose-valid-each-as/output.json +++ b/packages/svelte/tests/parser-modern/samples/loose-valid-each-as/output.json @@ -49,6 +49,18 @@ "start": 86, "end": 111, "name": "div", + "name_loc": { + "start": { + "line": 6, + "column": 2, + "character": 87 + }, + "end": { + "line": 6, + "column": 5, + "character": 90 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -293,6 +305,18 @@ "start": 8, "end": 17, "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, "value": [ { "start": 14, @@ -305,4 +329,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/options/output.json b/packages/svelte/tests/parser-modern/samples/options/output.json index 97e535156438..62c9fc1b9d52 100644 --- a/packages/svelte/tests/parser-modern/samples/options/output.json +++ b/packages/svelte/tests/parser-modern/samples/options/output.json @@ -32,6 +32,18 @@ "start": 16, "end": 49, "name": "customElement", + "name_loc": { + "start": { + "line": 1, + "column": 16, + "character": 16 + }, + "end": { + "line": 1, + "column": 29, + "character": 29 + } + }, "value": [ { "start": 31, @@ -47,6 +59,18 @@ "start": 50, "end": 62, "name": "runes", + "name_loc": { + "start": { + "line": 1, + "column": 50, + "character": 50 + }, + "end": { + "line": 1, + "column": 55, + "character": 55 + } + }, "value": { "type": "ExpressionTag", "start": 56, @@ -104,6 +128,18 @@ "start": 75, "end": 81, "name": "module", + "name_loc": { + "start": { + "line": 3, + "column": 8, + "character": 75 + }, + "end": { + "line": 3, + "column": 14, + "character": 81 + } + }, "value": true }, { @@ -111,6 +147,18 @@ "start": 82, "end": 91, "name": "lang", + "name_loc": { + "start": { + "line": 3, + "column": 15, + "character": 82 + }, + "end": { + "line": 3, + "column": 19, + "character": 86 + } + }, "value": [ { "start": 88, @@ -151,6 +199,18 @@ "start": 112, "end": 121, "name": "lang", + "name_loc": { + "start": { + "line": 6, + "column": 8, + "character": 112 + }, + "end": { + "line": 6, + "column": 12, + "character": 116 + } + }, "value": [ { "start": 118, @@ -166,6 +226,18 @@ "start": 122, "end": 158, "name": "generics", + "name_loc": { + "start": { + "line": 6, + "column": 18, + "character": 122 + }, + "end": { + "line": 6, + "column": 26, + "character": 130 + } + }, "value": [ { "start": 132, @@ -178,4 +250,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/semicolon-inside-quotes/output.json b/packages/svelte/tests/parser-modern/samples/semicolon-inside-quotes/output.json index ff452b356374..e95ccb409495 100644 --- a/packages/svelte/tests/parser-modern/samples/semicolon-inside-quotes/output.json +++ b/packages/svelte/tests/parser-modern/samples/semicolon-inside-quotes/output.json @@ -87,6 +87,18 @@ "start": 0, "end": 35, "name": "h1", + "name_loc": { + "start": { + "line": 1, + "column": 1, + "character": 1 + }, + "end": { + "line": 1, + "column": 3, + "character": 3 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -111,4 +123,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/snippets/output.json b/packages/svelte/tests/parser-modern/samples/snippets/output.json index 1baa53f7cf94..d760fe2e2dcf 100644 --- a/packages/svelte/tests/parser-modern/samples/snippets/output.json +++ b/packages/svelte/tests/parser-modern/samples/snippets/output.json @@ -20,9 +20,21 @@ "end": 81, "expression": { "type": "Identifier", + "name": "foo", "start": 39, "end": 42, - "name": "foo" + "loc": { + "start": { + "line": 3, + "column": 10, + "character": 39 + }, + "end": { + "line": 3, + "column": 13, + "character": 42 + } + } }, "parameters": [ { @@ -87,6 +99,18 @@ "start": 58, "end": 70, "name": "p", + "name_loc": { + "start": { + "line": 4, + "column": 2, + "character": 59 + }, + "end": { + "line": 4, + "column": 3, + "character": 60 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -218,6 +242,18 @@ "start": 8, "end": 17, "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, "value": [ { "start": 14, @@ -230,4 +266,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/template-shadowroot/output.json b/packages/svelte/tests/parser-modern/samples/template-shadowroot/output.json index 6039b6d52dab..2cc1dc498896 100644 --- a/packages/svelte/tests/parser-modern/samples/template-shadowroot/output.json +++ b/packages/svelte/tests/parser-modern/samples/template-shadowroot/output.json @@ -12,12 +12,36 @@ "start": 0, "end": 66, "name": "template", + "name_loc": { + "start": { + "line": 1, + "column": 1, + "character": 1 + }, + "end": { + "line": 1, + "column": 9, + "character": 9 + } + }, "attributes": [ { "type": "Attribute", "start": 10, "end": 31, "name": "shadowrootmode", + "name_loc": { + "start": { + "line": 1, + "column": 10, + "character": 10 + }, + "end": { + "line": 1, + "column": 24, + "character": 24 + } + }, "value": [ { "start": 26, @@ -44,6 +68,18 @@ "start": 34, "end": 54, "name": "p", + "name_loc": { + "start": { + "line": 2, + "column": 2, + "character": 35 + }, + "end": { + "line": 2, + "column": 3, + "character": 36 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -53,6 +89,18 @@ "start": 37, "end": 50, "name": "slot", + "name_loc": { + "start": { + "line": 2, + "column": 5, + "character": 38 + }, + "end": { + "line": 2, + "column": 9, + "character": 42 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -84,6 +132,18 @@ "start": 67, "end": 111, "name": "template", + "name_loc": { + "start": { + "line": 4, + "column": 1, + "character": 68 + }, + "end": { + "line": 4, + "column": 9, + "character": 76 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -100,6 +160,18 @@ "start": 79, "end": 99, "name": "p", + "name_loc": { + "start": { + "line": 5, + "column": 2, + "character": 80 + }, + "end": { + "line": 5, + "column": 3, + "character": 81 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -109,6 +181,18 @@ "start": 82, "end": 95, "name": "slot", + "name_loc": { + "start": { + "line": 5, + "column": 5, + "character": 83 + }, + "end": { + "line": 5, + "column": 9, + "character": 87 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -140,6 +224,18 @@ "start": 112, "end": 125, "name": "slot", + "name_loc": { + "start": { + "line": 7, + "column": 1, + "character": 113 + }, + "end": { + "line": 7, + "column": 5, + "character": 117 + } + }, "attributes": [], "fragment": { "type": "Fragment", @@ -149,4 +245,4 @@ ] }, "options": null -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/samples/typescript-in-event-handler/output.json b/packages/svelte/tests/parser-modern/samples/typescript-in-event-handler/output.json index a53e1eeebfda..4281d6fa4615 100644 --- a/packages/svelte/tests/parser-modern/samples/typescript-in-event-handler/output.json +++ b/packages/svelte/tests/parser-modern/samples/typescript-in-event-handler/output.json @@ -19,12 +19,36 @@ "start": 54, "end": 173, "name": "button", + "name_loc": { + "start": { + "line": 5, + "column": 1, + "character": 55 + }, + "end": { + "line": 5, + "column": 7, + "character": 61 + } + }, "attributes": [ { "start": 63, "end": 147, "type": "OnDirective", "name": "click", + "name_loc": { + "start": { + "line": 6, + "column": 1, + "character": 63 + }, + "end": { + "line": 6, + "column": 9, + "character": 71 + } + }, "expression": { "type": "ArrowFunctionExpression", "start": 73, @@ -485,6 +509,18 @@ "start": 8, "end": 17, "name": "lang", + "name_loc": { + "start": { + "line": 1, + "column": 8, + "character": 8 + }, + "end": { + "line": 1, + "column": 12, + "character": 12 + } + }, "value": [ { "start": 14, @@ -497,4 +533,4 @@ } ] } -} \ No newline at end of file +} diff --git a/packages/svelte/tests/parser-modern/test.ts b/packages/svelte/tests/parser-modern/test.ts index e38bfc7525e4..fb762e89e19e 100644 --- a/packages/svelte/tests/parser-modern/test.ts +++ b/packages/svelte/tests/parser-modern/test.ts @@ -29,7 +29,7 @@ const { test, run } = suite(async (config, cwd) => { // run `UPDATE_SNAPSHOTS=true pnpm test parser` to update parser tests if (process.env.UPDATE_SNAPSHOTS) { - fs.writeFileSync(`${cwd}/output.json`, JSON.stringify(actual, null, '\t')); + fs.writeFileSync(`${cwd}/output.json`, JSON.stringify(actual, null, '\t') + '\n'); } else { fs.writeFileSync(`${cwd}/_actual.json`, JSON.stringify(actual, null, '\t')); @@ -66,6 +66,8 @@ function clean(ast: AST.SvelteNode) { // @ts-ignore delete node.loc; // @ts-ignore + delete node.name_loc; + // @ts-ignore delete node.leadingComments; // @ts-ignore delete node.trailingComments; @@ -132,6 +134,18 @@ it('Strips BOM from the input', () => { nodes: [], type: 'Fragment' }, + name_loc: { + end: { + character: 4, + column: 4, + line: 1 + }, + start: { + character: 1, + column: 1, + line: 1 + } + }, name: 'div', start: 0, type: 'RegularElement' diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index 8561268689ca..0e6b019b62e6 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -842,7 +842,7 @@ declare module 'svelte/attachments' { declare module 'svelte/compiler' { import type { SourceMap } from 'magic-string'; - import type { ArrayExpression, ArrowFunctionExpression, VariableDeclaration, VariableDeclarator, Expression, Identifier, MemberExpression, Node, ObjectExpression, Pattern, Program, ChainExpression, SimpleCallExpression, SequenceExpression } from 'estree'; + import type { ArrayExpression, ArrowFunctionExpression, VariableDeclaration, VariableDeclarator, Expression, Identifier, MemberExpression, Node, ObjectExpression, Pattern, Program, ChainExpression, SimpleCallExpression, SequenceExpression, SourceLocation } from 'estree'; import type { Location } from 'locate-character'; import type { default as ts } from 'esrap/languages/ts'; /** @@ -1302,7 +1302,7 @@ declare module 'svelte/compiler' { } /** An `animate:` directive */ - export interface AnimateDirective extends BaseNode { + export interface AnimateDirective extends BaseAttribute { type: 'AnimateDirective'; /** The 'x' in `animate:x` */ name: string; @@ -1311,7 +1311,7 @@ declare module 'svelte/compiler' { } /** A `bind:` directive */ - export interface BindDirective extends BaseNode { + export interface BindDirective extends BaseAttribute { type: 'BindDirective'; /** The 'x' in `bind:x` */ name: string; @@ -1320,7 +1320,7 @@ declare module 'svelte/compiler' { } /** A `class:` directive */ - export interface ClassDirective extends BaseNode { + export interface ClassDirective extends BaseAttribute { type: 'ClassDirective'; /** The 'x' in `class:x` */ name: 'class'; @@ -1329,7 +1329,7 @@ declare module 'svelte/compiler' { } /** A `let:` directive */ - export interface LetDirective extends BaseNode { + export interface LetDirective extends BaseAttribute { type: 'LetDirective'; /** The 'x' in `let:x` */ name: string; @@ -1338,7 +1338,7 @@ declare module 'svelte/compiler' { } /** An `on:` directive */ - export interface OnDirective extends BaseNode { + export interface OnDirective extends BaseAttribute { type: 'OnDirective'; /** The 'x' in `on:x` */ name: string; @@ -1358,7 +1358,7 @@ declare module 'svelte/compiler' { } /** A `style:` directive */ - export interface StyleDirective extends BaseNode { + export interface StyleDirective extends BaseAttribute { type: 'StyleDirective'; /** The 'x' in `style:x` */ name: string; @@ -1369,7 +1369,7 @@ declare module 'svelte/compiler' { // TODO have separate in/out/transition directives /** A `transition:`, `in:` or `out:` directive */ - export interface TransitionDirective extends BaseNode { + export interface TransitionDirective extends BaseAttribute { type: 'TransitionDirective'; /** The 'x' in `transition:x` */ name: string; @@ -1383,7 +1383,7 @@ declare module 'svelte/compiler' { } /** A `use:` directive */ - export interface UseDirective extends BaseNode { + export interface UseDirective extends BaseAttribute { type: 'UseDirective'; /** The 'x' in `use:x` */ name: string; @@ -1393,6 +1393,7 @@ declare module 'svelte/compiler' { export interface BaseElement extends BaseNode { name: string; + name_loc: SourceLocation; attributes: Array; fragment: Fragment; } @@ -1517,9 +1518,13 @@ declare module 'svelte/compiler' { body: Fragment; } - export interface Attribute extends BaseNode { - type: 'Attribute'; + export interface BaseAttribute extends BaseNode { name: string; + name_loc: SourceLocation | null; + } + + export interface Attribute extends BaseAttribute { + type: 'Attribute'; /** * Quoted/string values are represented by an array, even if they contain a single expression like `"{x}"` */