-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
transform
function to annotate a function to be transform…
…ed by the vite plugin
- Loading branch information
1 parent
c32c994
commit 81c1bba
Showing
13 changed files
with
716 additions
and
25 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// Reexport your entry components here | ||
import { didCancel, timeout } from './utils'; | ||
import { didCancel, timeout, transform } from './utils'; | ||
import { task, CancelationError } from './task.js'; | ||
export type { Task, SheepdogUtils, TaskInstance } from './task.js'; | ||
|
||
export { task, CancelationError, didCancel, timeout }; | ||
export { task, CancelationError, didCancel, timeout, transform }; |
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
143 changes: 143 additions & 0 deletions
143
packages/svelte/src/lib/tests/expected-transforms/wrapped-in-transform-renamed/code.js
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,143 @@ | ||
import { transform as transform_renamed } from '@sheepdog/svelte/utils'; | ||
|
||
/** | ||
* @param {()=>any} fn | ||
*/ | ||
function transform(fn) { | ||
return fn; | ||
} | ||
|
||
/** | ||
* @param {number} val | ||
*/ | ||
function fn(val) { | ||
return val; | ||
} | ||
|
||
/** | ||
* @type {Record<string,()=>void>} | ||
*/ | ||
const fns = {}; | ||
|
||
/** | ||
* | ||
* @param {TemplateStringsArray} quasi | ||
* @param {string} strings | ||
*/ | ||
function str(quasi, strings) {} | ||
|
||
export const task_fn = transform_renamed(async () => { | ||
const assign = await Promise.resolve(); | ||
let assignment = null; | ||
assignment = await Promise.resolve(); | ||
const array = [await Promise.resolve()]; | ||
const sum = (await Promise.resolve(1)) + 2; | ||
const sum2 = 2 + (await Promise.resolve(1)); | ||
fns[await Promise.resolve(0)](); | ||
const [array_destructure = await Promise.resolve()] = [undefined]; | ||
const function_call = fn(await Promise.resolve(2)); | ||
const conditional1 = (await Promise.resolve(true)) ? 1 : 2; | ||
const conditional2 = true ? await Promise.resolve(1) : 2; | ||
const conditional3 = false ? 1 : await Promise.resolve(2); | ||
const member = { property: null }; | ||
member[await Promise.resolve('property')] = await Promise.resolve(null); | ||
const logical1 = (await Promise.resolve(null)) ?? 3; | ||
const logical2 = null ?? (await Promise.resolve(null)); | ||
const logical3 = null || (await Promise.resolve(null)); | ||
const logical4 = (await Promise.resolve(null)) || null; | ||
const logical5 = (await Promise.resolve(null)) && null; | ||
const logical6 = true && (await Promise.resolve(null)); | ||
const object_expression1 = { awaited: await Promise.resolve(2) }; | ||
const object_expression2 = { awaited: { nested: await Promise.resolve(2) } }; | ||
const object_expression3 = { awaited: { nested: [await Promise.resolve(2)] } }; | ||
const tagged_template = str`something ${await Promise.resolve('')}`; | ||
const template_literal = `something ${await Promise.resolve('')}`; | ||
const unary = !(await Promise.resolve(true)); | ||
}); | ||
|
||
const task_fn_no_export = transform_renamed(async () => { | ||
const assign = await Promise.resolve(); | ||
let assignment = null; | ||
assignment = await Promise.resolve(); | ||
const array = [await Promise.resolve()]; | ||
const sum = (await Promise.resolve(1)) + 2; | ||
const sum2 = 2 + (await Promise.resolve(1)); | ||
fns[await Promise.resolve(0)](); | ||
const [array_destructure = await Promise.resolve()] = [undefined]; | ||
const function_call = fn(await Promise.resolve(2)); | ||
const conditional1 = (await Promise.resolve(true)) ? 1 : 2; | ||
const conditional2 = true ? await Promise.resolve(1) : 2; | ||
const conditional3 = false ? 1 : await Promise.resolve(2); | ||
const member = { property: null }; | ||
member[await Promise.resolve('property')] = await Promise.resolve(null); | ||
const logical1 = (await Promise.resolve(null)) ?? 3; | ||
const logical2 = null ?? (await Promise.resolve(null)); | ||
const logical3 = null || (await Promise.resolve(null)); | ||
const logical4 = (await Promise.resolve(null)) || null; | ||
const logical5 = (await Promise.resolve(null)) && null; | ||
const logical6 = true && (await Promise.resolve(null)); | ||
const object_expression1 = { awaited: await Promise.resolve(2) }; | ||
const object_expression2 = { awaited: { nested: await Promise.resolve(2) } }; | ||
const object_expression3 = { awaited: { nested: [await Promise.resolve(2)] } }; | ||
const tagged_template = str`something ${await Promise.resolve('')}`; | ||
const template_literal = `something ${await Promise.resolve('')}`; | ||
const unary = !(await Promise.resolve(true)); | ||
}); | ||
|
||
async function with_no_transform() { | ||
const assign = await Promise.resolve(); | ||
let assignment = null; | ||
assignment = await Promise.resolve(); | ||
const array = [await Promise.resolve()]; | ||
const sum = (await Promise.resolve(1)) + 2; | ||
const sum2 = 2 + (await Promise.resolve(1)); | ||
fns[await Promise.resolve(0)](); | ||
const [array_destructure = await Promise.resolve()] = [undefined]; | ||
const function_call = fn(await Promise.resolve(2)); | ||
const conditional1 = (await Promise.resolve(true)) ? 1 : 2; | ||
const conditional2 = true ? await Promise.resolve(1) : 2; | ||
const conditional3 = false ? 1 : await Promise.resolve(2); | ||
const member = { property: null }; | ||
member[await Promise.resolve('property')] = await Promise.resolve(null); | ||
const logical1 = (await Promise.resolve(null)) ?? 3; | ||
const logical2 = null ?? (await Promise.resolve(null)); | ||
const logical3 = null || (await Promise.resolve(null)); | ||
const logical4 = (await Promise.resolve(null)) || null; | ||
const logical5 = (await Promise.resolve(null)) && null; | ||
const logical6 = true && (await Promise.resolve(null)); | ||
const object_expression1 = { awaited: await Promise.resolve(2) }; | ||
const object_expression2 = { awaited: { nested: await Promise.resolve(2) } }; | ||
const object_expression3 = { awaited: { nested: [await Promise.resolve(2)] } }; | ||
const tagged_template = str`something ${await Promise.resolve('')}`; | ||
const template_literal = `something ${await Promise.resolve('')}`; | ||
const unary = !(await Promise.resolve(true)); | ||
} | ||
|
||
const different_transform = transform(async () => { | ||
const assign = await Promise.resolve(); | ||
let assignment = null; | ||
assignment = await Promise.resolve(); | ||
const array = [await Promise.resolve()]; | ||
const sum = (await Promise.resolve(1)) + 2; | ||
const sum2 = 2 + (await Promise.resolve(1)); | ||
fns[await Promise.resolve(0)](); | ||
const [array_destructure = await Promise.resolve()] = [undefined]; | ||
const function_call = fn(await Promise.resolve(2)); | ||
const conditional1 = (await Promise.resolve(true)) ? 1 : 2; | ||
const conditional2 = true ? await Promise.resolve(1) : 2; | ||
const conditional3 = false ? 1 : await Promise.resolve(2); | ||
const member = { property: null }; | ||
member[await Promise.resolve('property')] = await Promise.resolve(null); | ||
const logical1 = (await Promise.resolve(null)) ?? 3; | ||
const logical2 = null ?? (await Promise.resolve(null)); | ||
const logical3 = null || (await Promise.resolve(null)); | ||
const logical4 = (await Promise.resolve(null)) || null; | ||
const logical5 = (await Promise.resolve(null)) && null; | ||
const logical6 = true && (await Promise.resolve(null)); | ||
const object_expression1 = { awaited: await Promise.resolve(2) }; | ||
const object_expression2 = { awaited: { nested: await Promise.resolve(2) } }; | ||
const object_expression3 = { awaited: { nested: [await Promise.resolve(2)] } }; | ||
const tagged_template = str`something ${await Promise.resolve('')}`; | ||
const template_literal = `something ${await Promise.resolve('')}`; | ||
const unary = !(await Promise.resolve(true)); | ||
}); |
Oops, something went wrong.