fix: adjust `loc` property of `Program` nodes created from `<script>` elements (#17428)

* fix: adjust program location to prevent corrupted sourcemaps

* update changeset

* go the other way
pull/17431/head
Rich Harris 3 weeks ago committed by GitHub
parent 41e8643814
commit 044dce9da5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: adjust `loc` property of `Program` nodes created from `<script>` elements

@ -6,6 +6,7 @@ import { regex_not_newline_characters } from '../../patterns.js';
import * as e from '../../../errors.js';
import * as w from '../../../warnings.js';
import { is_text_attribute } from '../../../utils/ast.js';
import { locator } from '../../../state.js';
const regex_closing_script_tag = /<\/script\s*>/;
const regex_starts_with_closing_script_tag = /^<\/script\s*>/;
@ -39,9 +40,15 @@ export function read_script(parser, start, attributes) {
parser.acorn_error(err);
}
// TODO is this necessary?
ast.start = script_start;
if (ast.loc) {
// Acorn always uses `0` as the start of a `Program`, but for sourcemap purposes
// we need it to be the start of the `<script>` contents
({ line: ast.loc.start.line, column: ast.loc.start.column } = locator(start));
({ line: ast.loc.end.line, column: ast.loc.end.column } = locator(parser.index));
}
/** @type {'default' | 'module'} */
let context = 'default';

@ -63,7 +63,7 @@
},
"end": {
"line": 3,
"column": 0
"column": 9
}
},
"body": [

@ -73,7 +73,7 @@
},
"end": {
"line": 3,
"column": 0
"column": 9
}
},
"body": [

@ -21,7 +21,7 @@
},
"end": {
"line": 9,
"column": 0
"column": 9
}
},
"body": [

@ -190,7 +190,7 @@
},
"end": {
"line": 3,
"column": 0
"column": 9
}
},
"body": [

@ -258,7 +258,7 @@
},
"end": {
"line": 2,
"column": 0
"column": 9
}
},
"body": [],

@ -298,7 +298,7 @@
},
"end": {
"line": 31,
"column": 0
"column": 9
}
},
"body": [

@ -73,7 +73,7 @@
},
"end": {
"line": 3,
"column": 0
"column": 9
}
},
"body": [

@ -73,7 +73,7 @@
},
"end": {
"line": 3,
"column": 0
"column": 9
}
},
"body": [

@ -37,7 +37,7 @@
},
"end": {
"line": 3,
"column": 0
"column": 9
}
},
"body": [],

@ -24,12 +24,12 @@
"end": 77,
"loc": {
"start": {
"line": 1,
"line": 5,
"column": 0
},
"end": {
"line": 7,
"column": 0
"column": 9
}
},
"body": [
@ -84,7 +84,7 @@
},
"end": {
"line": 3,
"column": 0
"column": 9
}
},
"body": [

@ -73,7 +73,7 @@
},
"end": {
"line": 3,
"column": 0
"column": 9
}
},
"body": [

@ -72,8 +72,8 @@
"column": 0
},
"end": {
"line": 3,
"column": 0
"line": 8,
"column": 1
}
},
"body": [

@ -272,7 +272,7 @@
},
"end": {
"line": 3,
"column": 0
"column": 9
}
},
"body": [

@ -34,12 +34,12 @@
"end": 67,
"loc": {
"start": {
"line": 1,
"line": 2,
"column": 0
},
"end": {
"line": 4,
"column": 0
"column": 9
}
},
"body": [

@ -296,7 +296,7 @@
},
"end": {
"line": 2,
"column": 0
"column": 9
}
},
"body": [],

@ -227,7 +227,7 @@
},
"end": {
"line": 3,
"column": 0
"column": 9
}
},
"body": [

@ -111,12 +111,12 @@
"end": 93,
"loc": {
"start": {
"line": 1,
"line": 3,
"column": 0
},
"end": {
"line": 4,
"column": 0
"column": 9
}
},
"body": [],
@ -182,12 +182,12 @@
"end": 160,
"loc": {
"start": {
"line": 1,
"line": 6,
"column": 0
},
"end": {
"line": 7,
"column": 0
"column": 9
}
},
"body": [],

@ -93,7 +93,7 @@
},
"end": {
"line": 3,
"column": 0
"column": 9
}
},
"body": [],

@ -230,7 +230,7 @@
},
"end": {
"line": 1,
"column": 18
"column": 27
}
},
"body": [],

@ -396,7 +396,7 @@
},
"end": {
"line": 3,
"column": 0
"column": 9
}
},
"body": [

Loading…
Cancel
Save