Skip to content

Commit 3fe0090

Browse files
test: check syntax is not polyfilled
1 parent 818ed8e commit 3fe0090

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

test/index.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,23 @@ test("should handle empty source code", (t) => {
126126
assert.strictEqual(transformSync(null).code, "");
127127
assert.strictEqual(transformSync("").code, "");
128128
});
129+
130+
test("should not polyfill using Symbol.Dispose", (t) => {
131+
const inputCode = `
132+
class Resource {
133+
[Symbol.dispose]() { console.log("Disposed"); }
134+
}
135+
using r = new Resource();`;
136+
const { code } = transformSync(inputCode);
137+
assert.strictEqual(code, inputCode);
138+
});
139+
140+
test("should not polyfill using Symbol.asyncDispose", (t) => {
141+
const inputCode = `
142+
class AsyncResource {
143+
async [Symbol.asyncDispose]() { console.log("Async disposed"); }
144+
}
145+
await using r = new AsyncResource();`;
146+
const { code } = transformSync(inputCode);
147+
assert.strictEqual(code, inputCode);
148+
});

test/snapshots/transform.test.js.snapshot

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
exports[`should not polyfill using using Symbol.Dispose 1`] = `
2+
"class Resource {\\n [Symbol.dispose]() {\\n console.log(\\"Disposed\\");\\n }\\n}\\nusing r = new Resource()\\n;\\n"
3+
`;
4+
5+
exports[`should not polyfill using using Symbol.asyncDispose 1`] = `
6+
"class AsyncResource {\\n async [Symbol.asyncDispose]() {\\n console.log(\\"Async disposed\\");\\n }\\n}\\nawait using r = new AsyncResource()\\n"
7+
`;
8+
9+
exports[`should not transform TypeScript class decorators with multiple decorators 1`] = `
10+
"@sealed\\n@log\\nclass BugReport {\\n type = \\"report\\";\\n title;\\n constructor(t){\\n this.title = t;\\n }\\n}\\nfunction sealed(constructor) {\\n Object.seal(constructor);\\n Object.seal(constructor.prototype);\\n}\\nfunction log(constructor) {\\n console.log(\\"Creating instance of\\", constructor.name);\\n}\\noutput = new BugReport(\\"Test\\");\\n"
11+
`;
12+
113
exports[`should perform transformation with error 1`] = `
214
"var Foo = /*#__PURE__*/ function(Foo) {\\n Foo[Foo[\\"Bar\\"] = 7] = \\"Bar\\";\\n Foo[Foo[\\"Baz\\"] = 2] = \\"Baz\\";\\n return Foo;\\n}(Foo || {});\\noutput = 7;\\nthrow new Error(\\"foo\\");\\n"
315
`;
@@ -30,10 +42,6 @@ exports[`should perform transformation without source maps and filename 1`] = `
3042
"var Foo = /*#__PURE__*/ function(Foo) {\\n Foo[Foo[\\"Bar\\"] = 7] = \\"Bar\\";\\n Foo[Foo[\\"Baz\\"] = 2] = \\"Baz\\";\\n return Foo;\\n}(Foo || {});\\noutput = 7;\\n"
3143
`;
3244

33-
exports[`should transform TypeScript class decorators with multiple decorators 1`] = `
34-
"@sealed\\n@log\\nclass BugReport {\\n type = \\"report\\";\\n title;\\n constructor(t){\\n this.title = t;\\n }\\n}\\nfunction sealed(constructor) {\\n Object.seal(constructor);\\n Object.seal(constructor.prototype);\\n}\\nfunction log(constructor) {\\n console.log(\\"Creating instance of\\", constructor.name);\\n}\\noutput = new BugReport(\\"Test\\");\\n"
35-
`;
36-
3745
exports[`should transform TypeScript class fields 1`] = `
3846
"class Counter {\\n count = 0;\\n increment() {\\n this.count++;\\n }\\n}\\nconst counter = new Counter();\\ncounter.increment();\\noutput = counter.count;\\n"
3947
`;

test/transform.test.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ test("should transform TypeScript type annotations and type guards", (t) => {
182182
assert.strictEqual(result, true);
183183
});
184184

185-
test("should transform TypeScript class decorators with multiple decorators", (t) => {
185+
test("should not transform TypeScript class decorators with multiple decorators", (t) => {
186186
const inputCode = `
187187
@sealed
188188
@log
@@ -278,3 +278,29 @@ test("test noEmptyExport", (t) => {
278278
});
279279
t.assert.snapshot(code);
280280
});
281+
282+
test("should not polyfill using Symbol.Dispose", (t) => {
283+
const inputCode = `
284+
class Resource {
285+
[Symbol.dispose]() { console.log("Disposed"); }
286+
}
287+
using r = new Resource();`;
288+
const { code } = transformSync(inputCode, {
289+
mode: "transform",
290+
sourceMap: true,
291+
});
292+
t.assert.snapshot(code);
293+
});
294+
295+
test("should not polyfill using Symbol.asyncDispose", (t) => {
296+
const inputCode = `
297+
class AsyncResource {
298+
async [Symbol.asyncDispose]() { console.log("Async disposed"); }
299+
}
300+
await using r = new AsyncResource();`;
301+
const { code } = transformSync(inputCode, {
302+
mode: "transform",
303+
sourceMap: true,
304+
});
305+
t.assert.snapshot(code);
306+
});

0 commit comments

Comments
 (0)