Skip to content

Commit 2d8027c

Browse files
committed
breaking: remove allowSatisfies option, always parsed now
1 parent 35e1a3b commit 2d8027c

File tree

6 files changed

+8
-26
lines changed

6 files changed

+8
-26
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ Version 1.0 of `@sveltejs/acorn-typescript` has some breaking changes compared t
1414

1515
- Only named export (i.e. you have to do `import { tsPlugin } from '@sveltejs/acorn-typescript';`, a default export is no longer provided)
1616
- ESM only (no CJS build)
17+
- JSX parsing is disabled by default now (you can turn it back on by passing `{ jsx: true }`)
18+
- `allowSatisfies` option was removed, `satisfies` operator is always parsed now
1719

1820
Changelog of the project this originated from: https://github.com/TyrealHu/acorn-typescript/CHANGELOG.md

__test__/satisfies/index.test.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import { describe, it } from 'vitest';
2-
import { equalNode, parseSourceAllowSatisfies, parseSourceShouldThrowError } from '../utils';
2+
import { equalNode, parseSource } from '../utils';
33
import SatisfiesSnapshot from '../__snapshot__/satisfies';
44

55
describe('satisfies', function () {
66
it('normal', function () {
7-
const node = parseSourceAllowSatisfies('const a = 1 satisfies any');
7+
const node = parseSource('const a = 1 satisfies any');
88

99
equalNode(node, SatisfiesSnapshot.Normal);
1010
});
11-
12-
it('should error', function () {
13-
parseSourceShouldThrowError('const a = 1 satisfies any', 'Unexpected token (1:12)');
14-
});
1511
});

__test__/utils.ts

-14
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ export const JsxParser = acorn.Parser.extend(
1616
})
1717
);
1818

19-
export const AllowSatisfiesParser = acorn.Parser.extend(
20-
tsPlugin({
21-
allowSatisfies: true
22-
})
23-
);
24-
2519
export function equalNode(node, snapshot) {
2620
assert.deepEqual(JSON.parse(JSON.stringify(node)), snapshot, 'should be' + JSON.stringify(node));
2721
}
@@ -50,14 +44,6 @@ export function parseSource(input: string) {
5044
});
5145
}
5246

53-
export function parseSourceAllowSatisfies(input: string) {
54-
return AllowSatisfiesParser.parse(input, {
55-
sourceType: 'module',
56-
ecmaVersion: 'latest',
57-
locations: true
58-
});
59-
}
60-
6147
export function parseSourceShouldThrowError(input: string, message?: string) {
6248
try {
6349
Parser.parse(input, {

index.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Parser } from 'acorn';
22

33
export function tsPlugin(options?: {
44
dts?: boolean;
5-
allowSatisfies?: boolean;
65
/** Whether to use JSX. Defaults to false */
76
jsx?:
87
| boolean

src/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ export function tsPlugin(options?: {
150150
allowNamespaces?: boolean;
151151
allowNamespacedObjects?: boolean;
152152
};
153-
allowSatisfies?: boolean;
154153
}) {
155-
const { dts = false, allowSatisfies = false } = options || {};
154+
const { dts = false } = options || {};
156155
const disallowAmbiguousJSXLike = !!options?.jsx;
157156

158157
return function (Parser: typeof AcornParseClass) {
@@ -2897,7 +2896,7 @@ export function tsPlugin(options?: {
28972896
nodeType = 'TSAsExpression';
28982897
}
28992898

2900-
if (allowSatisfies && this.isContextual('satisfies')) {
2899+
if (this.isContextual('satisfies')) {
29012900
nodeType = 'TSSatisfiesExpression';
29022901
}
29032902

tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
"sourceMap": true,
1515
"strict": false
1616
},
17-
"include": ["./src/*", "./__test__/*"],
18-
"exclude": ["./__test__/__snapshots__/*"]
17+
"include": ["./src/**/*", "./__test__/**/*"],
18+
"exclude": ["./__test__/__snapshots__/**/*"]
1919
}

0 commit comments

Comments
 (0)