fix: switch to our fork acorn typescript plugin (#15393)

* fix: switch to our fork acorn typescript plugin

* changeset

* bump

* bump

* bump

* adjust snapshots

* this should be obsolete now

* bump

* bump
pull/15433/head
Simon H 6 months ago committed by GitHub
parent 0f2633736d
commit ef7fd96ccf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
chore: switch acorn-typescript plugin

@ -150,7 +150,7 @@
"@jridgewell/sourcemap-codec": "^1.5.0",
"@types/estree": "^1.0.5",
"acorn": "^8.12.1",
"acorn-typescript": "^1.4.13",
"@sveltejs/acorn-typescript": "^1.0.5",
"aria-query": "^5.3.1",
"axobject-query": "^4.1.0",
"clsx": "^2.1.1",

@ -1,11 +1,9 @@
/** @import { Comment, Program } from 'estree' */
/** @import { Node } from 'acorn' */
import * as acorn from 'acorn';
import { walk } from 'zimmerframe';
import { tsPlugin } from 'acorn-typescript';
import { locator } from '../../state.js';
import { tsPlugin } from '@sveltejs/acorn-typescript';
const ParserWithTS = acorn.Parser.extend(tsPlugin({ allowSatisfies: true }));
const ParserWithTS = acorn.Parser.extend(tsPlugin());
/**
* @param {string} source
@ -48,7 +46,6 @@ export function parse(source, typescript, is_script) {
}
}
if (typescript) amend(source, ast);
add_comments(ast);
return /** @type {Program} */ (ast);
@ -71,7 +68,6 @@ export function parse_expression_at(source, typescript, index) {
locations: true
});
if (typescript) amend(source, ast);
add_comments(ast);
return ast;
@ -173,42 +169,3 @@ function get_comment_handlers(source) {
}
};
}
/**
* Tidy up some stuff left behind by acorn-typescript
* @param {string} source
* @param {Node} node
*/
function amend(source, node) {
return walk(node, null, {
_(node, context) {
// @ts-expect-error
delete node.loc.start.index;
// @ts-expect-error
delete node.loc.end.index;
if (typeof node.loc?.end === 'number') {
const loc = locator(node.loc.end);
if (loc) {
node.loc.end = {
line: loc.line,
column: loc.column
};
}
}
if (
/** @type {any} */ (node).typeAnnotation &&
(node.end === undefined || node.end < node.start)
) {
// i think there might be a bug in acorn-typescript that prevents
// `end` from being assigned when there's a type annotation
let end = /** @type {any} */ (node).typeAnnotation.start;
while (/\s/.test(source[end - 1])) end -= 1;
node.end = end;
}
context.next();
}
});
}

@ -1,3 +0,0 @@
// Silence the acorn typescript errors through this ambient type definition + tsconfig.json path alias
// That way we can omit `"skipLibCheck": true` and catch other errors in our d.ts files
declare module 'acorn-typescript';

@ -75,7 +75,7 @@
"id": {
"type": "Identifier",
"start": 52,
"end": 57,
"end": 65,
"loc": {
"start": {
"line": 3,

@ -28,7 +28,7 @@
{
"type": "Identifier",
"start": 43,
"end": 46,
"end": 54,
"loc": {
"start": {
"line": 3,

@ -25,7 +25,6 @@
"end": 147,
"type": "OnDirective",
"name": "click",
"modifiers": [],
"expression": {
"type": "ArrowFunctionExpression",
"start": 73,
@ -48,7 +47,7 @@
{
"type": "Identifier",
"start": 74,
"end": 75,
"end": 87,
"loc": {
"start": {
"line": 6,
@ -155,7 +154,7 @@
"id": {
"type": "Identifier",
"start": 102,
"end": 106,
"end": 114,
"loc": {
"start": {
"line": 7,
@ -316,7 +315,8 @@
}
]
}
}
},
"modifiers": []
}
],
"fragment": {

@ -15,7 +15,6 @@
"allowJs": true,
"checkJs": true,
"paths": {
"acorn-typescript": ["./src/compiler/phases/1-parse/ambient.d.ts"],
"svelte": ["./src/index.d.ts"],
"svelte/action": ["./src/action/public.d.ts"],
"svelte/compiler": ["./src/compiler/public.d.ts"],

@ -65,15 +65,15 @@ importers:
'@jridgewell/sourcemap-codec':
specifier: ^1.5.0
version: 1.5.0
'@sveltejs/acorn-typescript':
specifier: ^1.0.5
version: 1.0.5(acorn@8.14.0)
'@types/estree':
specifier: ^1.0.5
version: 1.0.6
acorn:
specifier: ^8.12.1
version: 8.14.0
acorn-typescript:
specifier: ^1.4.13
version: 1.4.13(acorn@8.14.0)
aria-query:
specifier: ^5.3.1
version: 5.3.1
@ -626,6 +626,11 @@ packages:
peerDependencies:
eslint: '>=8.40.0'
'@sveltejs/acorn-typescript@1.0.5':
resolution: {integrity: sha512-IwQk4yfwLdibDlrXVE04jTZYlLnwsTT2PIOQQGNLWfjavGifnk1JD1LcZjZaBTRcxZu2FfPfNLOE04DSu9lqtQ==}
peerDependencies:
acorn: ^8.9.0
'@sveltejs/eslint-config@8.1.0':
resolution: {integrity: sha512-cfgp4lPREYBjNd4ZzaP/jA85ufm7vfXiaV7h9vILXNogne80IbZRNhRCQ8XoOqTAOY/pChIzWTBuR8aDNMbAEA==}
peerDependencies:
@ -779,11 +784,6 @@ packages:
peerDependencies:
acorn: ^6.0.0 || ^7.0.0 || ^8.0.0
acorn-typescript@1.4.13:
resolution: {integrity: sha512-xsc9Xv0xlVfwp2o7sQ+GCQ1PgbkdcpWdTzrwXxO3xDMTAywVS3oXVOcOHuRjAPkS4P9b+yc/qNF15460v+jp4Q==}
peerDependencies:
acorn: '>=8.9.0'
acorn@8.14.0:
resolution: {integrity: sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==}
engines: {node: '>=0.4.0'}
@ -2720,6 +2720,10 @@ snapshots:
eslint-visitor-keys: 3.4.3
espree: 9.6.1
'@sveltejs/acorn-typescript@1.0.5(acorn@8.14.0)':
dependencies:
acorn: 8.14.0
'@sveltejs/eslint-config@8.1.0(@stylistic/eslint-plugin-js@1.8.0(eslint@9.9.1))(eslint-config-prettier@9.1.0(eslint@9.9.1))(eslint-plugin-n@17.9.0(eslint@9.9.1))(eslint-plugin-svelte@2.38.0(eslint@9.9.1)(svelte@packages+svelte))(eslint@9.9.1)(typescript-eslint@8.2.0(eslint@9.9.1)(typescript@5.5.4))(typescript@5.5.4)':
dependencies:
'@stylistic/eslint-plugin-js': 1.8.0(eslint@9.9.1)
@ -2926,10 +2930,6 @@ snapshots:
dependencies:
acorn: 8.14.0
acorn-typescript@1.4.13(acorn@8.14.0):
dependencies:
acorn: 8.14.0
acorn@8.14.0: {}
agent-base@7.1.1:

Loading…
Cancel
Save