-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: move assignment expression transformations behind flag (closes #2)
- Loading branch information
Showing
7 changed files
with
228 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
test/__fixtures__/transforms-assignment-expressions/code.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
function internalfn1() { | ||
fn1(); | ||
void Promise.all([1].map((_) => [fn2]).map((a) => a[0]())); | ||
} | ||
|
||
export function fn1() { | ||
global.console.log('hello, world!'); | ||
} | ||
|
||
export async function fn2() { | ||
fn1(); | ||
internalfn1(); | ||
} | ||
|
||
export async function fn3() { | ||
const f = fn1; | ||
await fn2(); | ||
f(); | ||
internalfn1(); | ||
} | ||
|
||
internalfn1(); | ||
void fn3(); | ||
|
||
export let var1: string; | ||
var1 = 'hello, world!'; | ||
var1 = 'goodbye, world!'; | ||
export let var2 = 2; | ||
var2 = 3; | ||
export let var3: boolean, var4: boolean; | ||
export let var5: boolean | string, var6: number; | ||
var5 = true; | ||
var5 = var1; | ||
var6 = 6; | ||
var6 = var2; | ||
|
||
export const var7 = 7, | ||
var8 = 8; | ||
export function fn4() { | ||
return var7 + var8; | ||
} | ||
|
||
let var9 = 9; | ||
var9 += 1; | ||
const var10 = var9; | ||
|
||
export class Class1 { | ||
val() { | ||
return var9; | ||
} | ||
} | ||
|
||
export class Class2 { | ||
val() { | ||
return var10 + var6; | ||
} | ||
} | ||
|
||
class Class3 { | ||
val() { | ||
return new Class1().val() + new Class2().val() + new Class3().life(); | ||
} | ||
|
||
life() { | ||
return 42; | ||
} | ||
} | ||
|
||
new Class3(); | ||
new Class2(); |
4 changes: 4 additions & 0 deletions
4
test/__fixtures__/transforms-assignment-expressions/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"fixtureOutputExt": ".mjs", | ||
"transformAssignExpr": true | ||
} |
66 changes: 66 additions & 0 deletions
66
test/__fixtures__/transforms-assignment-expressions/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
function internalfn1() { | ||
module.exports.fn1(); | ||
void Promise.all([1].map((_) => [module.exports.fn2]).map((a) => a[0]())); | ||
} | ||
|
||
export function fn1() { | ||
global.console.log('hello, world!'); | ||
} | ||
export async function fn2() { | ||
module.exports.fn1(); | ||
internalfn1(); | ||
} | ||
export async function fn3() { | ||
const f = module.exports.fn1; | ||
await module.exports.fn2(); | ||
f(); | ||
internalfn1(); | ||
} | ||
internalfn1(); | ||
void module.exports.fn3(); | ||
export let var1; | ||
module.exports.var1 = 'hello, world!'; | ||
module.exports.var1 = 'goodbye, world!'; | ||
export let var2 = 2; | ||
module.exports.var2 = 3; | ||
export let var3, var4; | ||
export let var5, var6; | ||
module.exports.var5 = true; | ||
module.exports.var5 = module.exports.var1; | ||
module.exports.var6 = 6; | ||
module.exports.var6 = module.exports.var2; | ||
export const var7 = 7, | ||
var8 = 8; | ||
export function fn4() { | ||
return module.exports.var7 + module.exports.var8; | ||
} | ||
let var9 = 9; | ||
var9 += 1; | ||
const var10 = var9; | ||
export class Class1 { | ||
val() { | ||
return var9; | ||
} | ||
} | ||
export class Class2 { | ||
val() { | ||
return var10 + module.exports.var6; | ||
} | ||
} | ||
|
||
class Class3 { | ||
val() { | ||
return ( | ||
new module.exports.Class1().val() + | ||
new module.exports.Class2().val() + | ||
new Class3().life() | ||
); | ||
} | ||
|
||
life() { | ||
return 42; | ||
} | ||
} | ||
|
||
new Class3(); | ||
new module.exports.Class2(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.