-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
158676e
commit a9909f3
Showing
29 changed files
with
395 additions
and
31 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 +1,2 @@ | ||
/lib | ||
/test/actual |
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ node_modules | |
.npmignore | ||
tsconfig.json | ||
*.map | ||
/test |
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
15 changes: 15 additions & 0 deletions
15
packages/ts-transform-emscripten-esm-library/test/expected/alias.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,15 @@ | ||
const _exportedVar = 10; | ||
function f() { | ||
console.log(_exportedVar); | ||
} | ||
function _exportedFunc() { | ||
f(); | ||
console.log(_exportedVar); | ||
} | ||
mergeInto(LibraryManager.library, { | ||
exportedVar: "10", | ||
$f: f, | ||
$f__deps: ["exportedVar"], | ||
exportedFunc: _exportedFunc, | ||
exportedFunc__deps: ["$f", "exportedVar"] | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/ts-transform-emscripten-esm-library/test/expected/bundle.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,12 @@ | ||
const fortyTwo = 42; | ||
function _x() { | ||
console.log(fortyTwo); | ||
} | ||
const _y = () => fortyTwo; | ||
mergeInto(LibraryManager.library, { | ||
$fortyTwo: "42", | ||
x: _x, | ||
x__deps: ["$fortyTwo"], | ||
y: _y, | ||
y__deps: ["$fortyTwo"] | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/ts-transform-emscripten-esm-library/test/expected/exported-function-ref.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,29 @@ | ||
/** @__deps $external */ | ||
function _x() { } | ||
/** | ||
* @__deps emscripten_resize_heap | ||
* @__deps $runtimeKeepalivePush | ||
* @__deps $runtimeKeepalivePop | ||
* @__sig v | ||
* @__postset | ||
* ``` | ||
* console.log(42); | ||
* console.log(_y); | ||
* ``` | ||
* | ||
* @returns {void} | ||
*/ | ||
function _y() { | ||
runtimeKeepalivePush(); | ||
runtimeKeepalivePop(); | ||
_emscripten_resize_heap(); | ||
return _x(); | ||
} | ||
mergeInto(LibraryManager.library, { | ||
x: _x, | ||
x__deps: ["$external"], | ||
y: _y, | ||
y__deps: ["x", "emscripten_resize_heap", "$runtimeKeepalivePush", "$runtimeKeepalivePop"], | ||
y__sig: "v", | ||
y__postset: "console.log(42);\nconsole.log(_y);" | ||
}); |
6 changes: 6 additions & 0 deletions
6
packages/ts-transform-emscripten-esm-library/test/expected/exported-function.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,6 @@ | ||
function _x() { | ||
return 42; | ||
} | ||
mergeInto(LibraryManager.library, { | ||
x: _x | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/ts-transform-emscripten-esm-library/test/expected/exported-var.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,9 @@ | ||
const _x = getX(); | ||
function getX() { | ||
return 42; | ||
} | ||
mergeInto(LibraryManager.library, { | ||
$getX: getX, | ||
x: "getX()", | ||
x__deps: ["$getX"] | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/ts-transform-emscripten-esm-library/test/expected/external-variable.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,13 @@ | ||
const fortyTwo = 42; | ||
const arr = new Uint8Array(fortyTwo); | ||
function _x(param) { | ||
const ret = arr; | ||
return param + ret; | ||
} | ||
mergeInto(LibraryManager.library, { | ||
$fortyTwo: "42", | ||
$arr: "new Uint8Array(fortyTwo)", | ||
$arr__deps: ["$fortyTwo"], | ||
x: _x, | ||
x__deps: ["$arr"] | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/ts-transform-emscripten-esm-library/test/expected/internal.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,22 @@ | ||
const fortyTwo = 42; | ||
const bar = fortyTwo; | ||
function x() { | ||
return fortyTwo; | ||
} | ||
function foo() { | ||
return fortyTwo; | ||
} | ||
function _z() { | ||
return foo(); | ||
} | ||
mergeInto(LibraryManager.library, { | ||
$fortyTwo: "42", | ||
$x: x, | ||
$x__deps: ["$fortyTwo"], | ||
$foo: foo, | ||
$foo__deps: ["$fortyTwo"], | ||
z: _z, | ||
z__deps: ["$foo"], | ||
$bar: "fortyTwo", | ||
$bar__deps: ["$fortyTwo"] | ||
}); |
48 changes: 48 additions & 0 deletions
48
packages/ts-transform-emscripten-esm-library/test/expected/object-literal.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,48 @@ | ||
const fortyTwo = 42; | ||
/** | ||
* @__sig ii | ||
* @param {number} _ | ||
*/ | ||
const _bar = _ => _; | ||
/** | ||
* @__postset | ||
* ``` | ||
* console.log(obj) | ||
* ``` | ||
*/ | ||
const obj = { | ||
foo: fortyTwo, | ||
bar(param) { | ||
_bar(param); | ||
} | ||
}; | ||
const arr = [fortyTwo]; | ||
/** | ||
* @__sig i | ||
*/ | ||
const _fe = function () { | ||
return obj.foo === arr[0]; | ||
}; | ||
/** | ||
* @__sig ii | ||
* @param {number} param | ||
*/ | ||
const _af = (param) => { | ||
obj.bar(param); | ||
}; | ||
mergeInto(LibraryManager.library, { | ||
bar: _bar, | ||
bar__sig: "ii", | ||
$fortyTwo: "42", | ||
$obj: obj, | ||
$obj__deps: ["$fortyTwo", "bar"], | ||
$obj__postset: "console.log(obj)", | ||
$arr: arr, | ||
$arr__deps: ["$fortyTwo"], | ||
fe: _fe, | ||
fe__deps: ["$obj", "$arr"], | ||
fe__sig: "i", | ||
af: _af, | ||
af__deps: ["$obj"], | ||
af__sig: "ii" | ||
}); |
51 changes: 51 additions & 0 deletions
51
packages/ts-transform-emscripten-esm-library/test/index.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,51 @@ | ||
const test = require('node:test') | ||
const { strictEqual } = require('assert') | ||
const { readFileSync, writeFileSync, mkdirSync } = require('fs') | ||
const { join, dirname } = require('path') | ||
const { rollup } = require('rollup') | ||
const { transform } = require('..') | ||
|
||
function testTransform (file) { | ||
const exportedFunction = join(__dirname, `input/${file}.js`) | ||
const exportedFunctionExpected = join(__dirname, `expected/${file}.js`) | ||
const actualFunctionExpected = join(__dirname, `actual/${file}.js`) | ||
const transformed = transform(exportedFunction, readFileSync(exportedFunction, 'utf8')) | ||
mkdirSync(dirname(actualFunctionExpected), { recursive: true }) | ||
writeFileSync(actualFunctionExpected, transformed, 'utf8') | ||
strictEqual(transformed, readFileSync(exportedFunctionExpected, 'utf8')) | ||
} | ||
|
||
test('exported function', () => { | ||
testTransform('exported-function') | ||
}) | ||
|
||
test('external variable', () => { | ||
testTransform('external-variable') | ||
}) | ||
|
||
test('exported function referenced by another one', () => { | ||
testTransform('exported-function-ref') | ||
}) | ||
|
||
test('exported local variable using a local function', () => { | ||
testTransform('exported-var') | ||
}) | ||
|
||
test('exporting a variable and a function with custom names', () => { | ||
testTransform('alias') | ||
}) | ||
|
||
test('object literal dependencies', () => { | ||
testTransform('object-literal') | ||
}) | ||
|
||
test('internal', () => { | ||
testTransform('internal') | ||
}) | ||
|
||
test('rollup', async () => { | ||
const config = (await import('./rollup/rollup.config.mjs')).default | ||
const build = await rollup(config) | ||
await build.write(config.output) | ||
strictEqual(readFileSync(config.output.file, 'utf8'), readFileSync(join(__dirname, './expected/bundle.js'), 'utf8')) | ||
}) |
15 changes: 15 additions & 0 deletions
15
packages/ts-transform-emscripten-esm-library/test/input/alias.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,15 @@ | ||
const localVar = 10 | ||
|
||
function f () { | ||
console.log(localVar) | ||
} | ||
|
||
function localFunc() { | ||
f() | ||
console.log(localVar) | ||
} | ||
|
||
export { | ||
localVar as exportedVar, | ||
localFunc as exportedFunc | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/ts-transform-emscripten-esm-library/test/input/exported-function-ref.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,22 @@ | ||
/** @__deps $external */ | ||
export function x() {} | ||
|
||
/** | ||
* @__deps emscripten_resize_heap | ||
* @__deps $runtimeKeepalivePush | ||
* @__deps $runtimeKeepalivePop | ||
* @__sig v | ||
* @__postset | ||
* ``` | ||
* console.log(42); | ||
* console.log(_y); | ||
* ``` | ||
* | ||
* @returns {void} | ||
*/ | ||
export function y() { | ||
runtimeKeepalivePush() | ||
runtimeKeepalivePop() | ||
_emscripten_resize_heap() | ||
return x() | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/ts-transform-emscripten-esm-library/test/input/exported-function.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,3 @@ | ||
export function x () { | ||
return 42 | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/ts-transform-emscripten-esm-library/test/input/exported-var.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,5 @@ | ||
export const x = getX() | ||
|
||
function getX() { | ||
return 42 | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/ts-transform-emscripten-esm-library/test/input/external-variable.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,7 @@ | ||
const fortyTwo = 42 | ||
const arr = new Uint8Array(fortyTwo) | ||
|
||
export function x (param) { | ||
const ret = arr | ||
return param + ret | ||
} |
Oops, something went wrong.