Skip to content

Commit 08f8b06

Browse files
committed
Fix plugin tests
1 parent a23eeb2 commit 08f8b06

4 files changed

Lines changed: 43 additions & 8 deletions

File tree

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`getModuleId 1`] = `
4-
"local ____exports = {}
5-
require(\\"5d05566c99dac259f6ff5742a268d405157a0d7c\\")
6-
return ____exports"
4+
"
5+
local ____modules = {}
6+
local ____moduleCache = {}
7+
local ____originalRequire = require
8+
local function require(file)
9+
if ____moduleCache[file] then
10+
return ____moduleCache[file]
11+
end
12+
if ____modules[file] then
13+
____moduleCache[file] = ____modules[file]()
14+
return ____moduleCache[file]
15+
else
16+
if ____originalRequire then
17+
return ____originalRequire(file)
18+
else
19+
error(\\"module '\\" .. file .. \\"' not found\\")
20+
end
21+
end
22+
end
23+
____modules = {
24+
[\\"5d05566c99dac259f6ff5742a268d405157a0d7c\\"] = function()
25+
local ____exports = {}
26+
____exports.value = true
27+
return ____exports
28+
29+
end,
30+
[\\"9124a2db32045398a4f097c567d1fe6fcb7ab900\\"] = function()
31+
local ____exports = {}
32+
do
33+
local ____foo = require(\\"5d05566c99dac259f6ff5742a268d405157a0d7c\\")
34+
local value = ____foo.value
35+
____exports.value = value
36+
end
37+
return ____exports
38+
39+
end,
40+
}
41+
return require(\\"9124a2db32045398a4f097c567d1fe6fcb7ab900\\")"
742
`;

test/transpile/plugins/getModuleId.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as tstl from "../../../src";
55
const plugin: tstl.Plugin = {
66
getModuleId: (module, transpilation) =>
77
createHash("sha1")
8-
.update(module.code)
8+
.update(module.source.toString())
99
.update(path.relative(transpilation.rootDir, module.request))
1010
.digest("hex"),
1111
};

test/transpile/plugins/plugins.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test("visitor using super", () => {
2424
});
2525

2626
test("getModuleId", () => {
27-
util.testModule`
27+
util.testBundle`
2828
export { value } from "./foo";
2929
`
3030
.addExtraFile("foo.ts", "export const value = true;")
@@ -34,7 +34,7 @@ test("getModuleId", () => {
3434
});
3535

3636
test("getResolvePlugins", () => {
37-
util.testModule`
37+
util.testBundle`
3838
export { value } from "foo";
3939
`
4040
.addExtraFile("bar.ts", "export const value = true;")

test/transpile/plugins/printer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { SourceNode } from "source-map";
12
import * as tstl from "../../../src";
23

34
const plugin: tstl.Plugin = {
45
printer(program, host, fileName, ...args) {
56
const result = new tstl.LuaPrinter(host, program, fileName).print(...args);
6-
result.code = `-- Plugin\n${result.code}`;
7-
return result;
7+
return new SourceNode(null, null, null, ["-- Plugin\n", result.source]);
88
},
99
};
1010

0 commit comments

Comments
 (0)