Skip to content

Commit 38c9e09

Browse files
committed
feat!: change the parser to an ESM-only package
1 parent 98135fb commit 38c9e09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+325
-310
lines changed

benchmark/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
/* eslint-disable no-console -- ignore */
33
import * as Benchmark from "benchmark";
44
import fs from "fs";
5-
import { parseForESLint } from "../src/index";
6-
import { parseForESLint as parseOld } from "../node_modules/svelte-eslint-parser";
5+
import { parseForESLint } from "../src/index.js";
6+
import { parseForESLint as parseOld } from "../node_modules/svelte-eslint-parser/lib/index.js";
77

88
const contents = `${fs.readFileSync(
99
require.resolve("../explorer-v2/src/lib/RulesSettings.svelte"),

explorer-v2/build-system/shim/module.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
// eslint-disable-next-line n/no-extraneous-import -- shim
2+
import * as estree from 'espree';
13
export function createRequire() {
2-
return null;
4+
function req(mod) {
5+
if (mod === 'espree') {
6+
return estree;
7+
}
8+
throw new Error(`Cannot find module '${mod}'`);
9+
}
10+
11+
req.cache = {};
12+
return req;
313
}
414
export default {
515
createRequire

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"engines": {
1515
"node": "^18.20.4 || ^20.18.0 || >=22.10.0"
1616
},
17-
"type": "commonjs",
17+
"type": "module",
1818
"main": "lib/index.js",
1919
"files": [
2020
"lib"
@@ -41,7 +41,7 @@
4141
"preversion": "pnpm run lint && pnpm run test",
4242
"release": "changeset publish",
4343
"test": "pnpm run mocha \"tests/src/**/*.ts\" --reporter dot --timeout 60000",
44-
"ts": "node -r esbuild-register",
44+
"ts": "node --import tsx/esm",
4545
"update-fixtures": "git add package.json && pnpm i -D svelte@4 && git checkout package.json && pnpm run run-update-fixtures && pnpm i && pnpm run run-update-fixtures",
4646
"run-update-fixtures": "pnpm run ts ./tools/update-fixtures.ts",
4747
"version:ci": "env-cmd -e version-ci pnpm run build:meta && changeset version"
@@ -82,7 +82,6 @@
8282
"chai": "^4.5.0",
8383
"env-cmd": "^10.1.0",
8484
"esbuild": "^0.24.0",
85-
"esbuild-register": "^3.6.0",
8685
"eslint": "~9.16.0",
8786
"eslint-config-prettier": "^9.1.0",
8887
"eslint-plugin-eslint-comments": "^3.2.0",
@@ -108,6 +107,7 @@
108107
"semver": "^7.6.3",
109108
"svelte": "^5.2.11",
110109
"svelte2tsx": "^0.7.28",
110+
"tsx": "^4.19.2",
111111
"typescript": "~5.7.2",
112112
"typescript-eslint": "^8.16.0",
113113
"typescript-eslint-parser-for-extra-files": "^0.7.0"

src/ast/base.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Locations } from "./common";
1+
import type { Locations } from "./common.js";
22

33
// internals
44
export interface BaseNode extends Locations {

src/ast/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { BaseNode } from "./base";
1+
import type { BaseNode } from "./base.js";
22

33
export interface Position {
44
/** >= 1 */

src/ast/html.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type ESTree from "estree";
22
import type { TSESTree } from "@typescript-eslint/types";
3-
import type { BaseNode } from "./base";
4-
import type { Token, Comment } from "./common";
3+
import type { BaseNode } from "./base.js";
4+
import type { Token, Comment } from "./common.js";
55

66
export type SvelteHTMLNode =
77
| SvelteProgram

src/ast/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { SvelteHTMLNode } from "./html";
2-
import type { SvelteScriptNode } from "./script";
1+
import type { SvelteHTMLNode } from "./html.js";
2+
import type { SvelteScriptNode } from "./script.js";
33

4-
export * from "./common";
5-
export * from "./html";
6-
export * from "./script";
4+
export * from "./common.js";
5+
export * from "./html.js";
6+
export * from "./script.js";
77

88
export type SvelteNode = SvelteHTMLNode | SvelteScriptNode;

src/ast/script.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type ESTree from "estree";
2-
import type { BaseNode } from "./base";
2+
import type { BaseNode } from "./base.js";
33

44
export type SvelteScriptNode = SvelteReactiveStatement;
55

src/context/fix-locations.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type * as ESTree from "estree";
2-
import type { Comment, Locations, Token } from "../ast";
3-
import type { Context } from ".";
4-
import { traverseNodes } from "../traverse";
2+
import type { Comment, Locations, Token } from "../ast/index.js";
3+
import type { Context } from "./index.js";
4+
import { traverseNodes } from "../traverse.js";
55

66
/** Fix locations */
77
export function fixLocations(

src/context/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ import type {
99
SvelteSnippetBlock,
1010
SvelteStyleElement,
1111
Token,
12-
} from "../ast";
12+
} from "../ast/index.js";
1313
import type ESTree from "estree";
14-
import type * as SvAST from "../parser/svelte-ast-types";
15-
import type * as Compiler from "../parser/svelte-ast-types-for-v5";
16-
import { ScriptLetContext } from "./script-let";
17-
import { LetDirectiveCollections } from "./let-directive-collection";
18-
import { parseAttributes } from "../parser/html";
19-
import { sortedLastIndex } from "../utils";
14+
import type * as SvAST from "../parser/svelte-ast-types.js";
15+
import type * as Compiler from "../parser/svelte-ast-types-for-v5.js";
16+
import { ScriptLetContext } from "./script-let.js";
17+
import { LetDirectiveCollections } from "./let-directive-collection.js";
18+
import { parseAttributes } from "../parser/html.js";
19+
import { sortedLastIndex } from "../utils/index.js";
2020
import {
2121
isTypeScript,
2222
type NormalizedParserOptions,
23-
} from "../parser/parser-options";
23+
} from "../parser/parser-options.js";
2424

2525
export class ScriptsSourceCode {
2626
private raw: string;

0 commit comments

Comments
 (0)