mirror of https://github.com/sveltejs/svelte
parent
36a0b717d4
commit
6f61b5d70d
@ -1,31 +1,18 @@
|
||||
import { update_expected } from "../update";
|
||||
import { loadConfig, update_expected } from "../helpers";
|
||||
|
||||
export function sanitize(compiled){
|
||||
return compiled.js.code.replace(/generated by Svelte v\d+\.\d+\.\d+(-\w+\.\d+)?/, 'generated by Svelte vX.Y.Z');
|
||||
}
|
||||
|
||||
// this file will replace all the expected.js files with their _actual
|
||||
// equivalents. Only use it when you're sure that you haven't
|
||||
// broken anything!
|
||||
|
||||
function loadConfig(file) {
|
||||
try {
|
||||
const resolved = require.resolve(file);
|
||||
delete require.cache[resolved];
|
||||
|
||||
const config = require(resolved);
|
||||
return config.default || config;
|
||||
} catch (err) {
|
||||
if (err.code === "MODULE_NOT_FOUND") {
|
||||
return {};
|
||||
}
|
||||
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
update_expected((compile, check, get_relative) => {
|
||||
update_expected(
|
||||
(compile, check, get_relative) =>
|
||||
check(
|
||||
"expected.js",
|
||||
compile(loadConfig(get_relative("_config.js")).options).js.code.replace(
|
||||
/generated by Svelte v\d+\.\d+\.\d+(-\w+\.\d+)?/,
|
||||
"generated by Svelte vX.Y.Z"
|
||||
)
|
||||
);
|
||||
}, __dirname);
|
||||
sanitize(compile(loadConfig(get_relative("_config.js")).options))
|
||||
),
|
||||
__dirname
|
||||
);
|
||||
|
@ -1,19 +1,27 @@
|
||||
import { update_expected } from "../update";
|
||||
|
||||
export function sanitize_ast(compiled){
|
||||
return compiled.ast;
|
||||
}
|
||||
|
||||
export function sanitize_error(e){
|
||||
return {
|
||||
code: e.code,
|
||||
message: e.message,
|
||||
start: e.start,
|
||||
pos: e.pos
|
||||
}
|
||||
}
|
||||
|
||||
// this file will replace all the expected.js files with their _actual
|
||||
// equivalents. Only use it when you're sure that you haven't
|
||||
// broken anything!
|
||||
|
||||
update_expected((compile, check) => {
|
||||
try {
|
||||
check("output.json", compile({ generate: false }).ast);
|
||||
check("output.json", sanitize_ast(compile({ generate: false })));
|
||||
} catch (e) {
|
||||
if (e.name !== "ParseError") throw e;
|
||||
check("error.json", {
|
||||
code: e.code,
|
||||
message: e.message,
|
||||
start: e.start,
|
||||
pos: e.pos,
|
||||
});
|
||||
check("error.json", sanitize_error(e));
|
||||
}
|
||||
}, __dirname);
|
||||
|
Loading…
Reference in new issue