mirror of
https://github.com/sveltejs/svelte.git
synced 2024-11-29 08:32:05 +01:00
commit
89b00c7d30
@ -26,8 +26,6 @@ function collapseTimings(timings) {
|
||||
}
|
||||
|
||||
export default class Stats {
|
||||
onwarn: (warning: Warning) => void;
|
||||
|
||||
startTime: number;
|
||||
currentTiming: Timing;
|
||||
currentChildren: Timing[];
|
||||
@ -35,15 +33,11 @@ export default class Stats {
|
||||
stack: Timing[];
|
||||
warnings: Warning[];
|
||||
|
||||
constructor({ onwarn }: {
|
||||
onwarn: (warning: Warning) => void
|
||||
}) {
|
||||
constructor() {
|
||||
this.startTime = now();
|
||||
this.stack = [];
|
||||
this.currentChildren = this.timings = [];
|
||||
|
||||
this.onwarn = onwarn;
|
||||
|
||||
this.warnings = [];
|
||||
}
|
||||
|
||||
@ -114,6 +108,5 @@ export default class Stats {
|
||||
|
||||
warn(warning) {
|
||||
this.warnings.push(warning);
|
||||
this.onwarn(warning);
|
||||
}
|
||||
}
|
||||
|
@ -54,11 +54,7 @@ function get_name(filename) {
|
||||
export default function compile(source: string, options: CompileOptions = {}) {
|
||||
options = assign({ generate: 'dom', dev: false }, options);
|
||||
|
||||
const stats = new Stats({
|
||||
onwarn: options.onwarn
|
||||
? (warning: Warning) => options.onwarn(warning, default_onwarn)
|
||||
: default_onwarn
|
||||
});
|
||||
const stats = new Stats();
|
||||
|
||||
let ast: Ast;
|
||||
|
||||
|
@ -49,7 +49,6 @@ export default class Node {
|
||||
}
|
||||
|
||||
warnIfEmptyBlock() {
|
||||
if (!this.component.compileOptions.dev) return;
|
||||
if (!/Block$/.test(this.type) || !this.children) return;
|
||||
if (this.children.length > 1) return;
|
||||
|
||||
|
@ -60,8 +60,6 @@ export interface CompileOptions {
|
||||
css?: boolean;
|
||||
|
||||
preserveComments?: boolean | false;
|
||||
|
||||
onwarn?: (warning: Warning, default_onwarn?: (warning: Warning) => void) => void;
|
||||
}
|
||||
|
||||
export interface Visitor {
|
||||
|
@ -2,7 +2,7 @@ import * as assert from 'assert';
|
||||
import * as fs from 'fs';
|
||||
import { env, normalizeHtml, svelte } from '../helpers.js';
|
||||
|
||||
function tryRequire(file) {
|
||||
function try_require(file) {
|
||||
try {
|
||||
const mod = require(file);
|
||||
return mod.default || mod;
|
||||
@ -12,7 +12,7 @@ function tryRequire(file) {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeWarning(warning) {
|
||||
function normalize_warning(warning) {
|
||||
warning.frame = warning.frame
|
||||
.replace(/^\n/, '')
|
||||
.replace(/^\t+/gm, '')
|
||||
@ -49,47 +49,30 @@ describe('css', () => {
|
||||
}
|
||||
|
||||
(solo ? it.only : skip ? it.skip : it)(dir, () => {
|
||||
const config = tryRequire(`./samples/${dir}/_config.js`) || {};
|
||||
const config = try_require(`./samples/${dir}/_config.js`) || {};
|
||||
const input = fs
|
||||
.readFileSync(`test/css/samples/${dir}/input.svelte`, 'utf-8')
|
||||
.replace(/\s+$/, '');
|
||||
|
||||
const expectedWarnings = (config.warnings || []).map(normalizeWarning);
|
||||
const domWarnings = [];
|
||||
const ssrWarnings = [];
|
||||
const expected_warnings = (config.warnings || []).map(normalize_warning);
|
||||
|
||||
const dom = svelte.compile(
|
||||
input,
|
||||
Object.assign(config, {
|
||||
format: 'cjs',
|
||||
onwarn: warning => {
|
||||
domWarnings.push(warning);
|
||||
}
|
||||
})
|
||||
Object.assign(config, { format: 'cjs' })
|
||||
);
|
||||
|
||||
assert.deepEqual(dom.stats.warnings, domWarnings);
|
||||
|
||||
const ssr = svelte.compile(
|
||||
input,
|
||||
Object.assign(config, {
|
||||
format: 'cjs',
|
||||
generate: 'ssr',
|
||||
onwarn: warning => {
|
||||
ssrWarnings.push(warning);
|
||||
}
|
||||
})
|
||||
Object.assign(config, { format: 'cjs', generate: 'ssr' })
|
||||
);
|
||||
|
||||
assert.deepEqual(dom.stats.warnings, domWarnings);
|
||||
|
||||
assert.equal(dom.css.code, ssr.css.code);
|
||||
|
||||
assert.deepEqual(
|
||||
domWarnings.map(normalizeWarning),
|
||||
ssrWarnings.map(normalizeWarning)
|
||||
);
|
||||
assert.deepEqual(domWarnings.map(normalizeWarning), expectedWarnings);
|
||||
const dom_warnings = dom.stats.warnings.map(normalize_warning);
|
||||
const ssr_warnings = ssr.stats.warnings.map(normalize_warning);
|
||||
|
||||
assert.deepEqual(dom_warnings, ssr_warnings);
|
||||
assert.deepEqual(dom_warnings.map(normalize_warning), expected_warnings);
|
||||
|
||||
fs.writeFileSync(`test/css/samples/${dir}/_actual.css`, dom.css.code);
|
||||
const expected = {
|
||||
|
@ -18,42 +18,32 @@ describe("validate", () => {
|
||||
const config = loadConfig(`./validator/samples/${dir}/_config.js`);
|
||||
|
||||
const input = fs.readFileSync(`test/validator/samples/${dir}/input.svelte`, "utf-8").replace(/\s+$/, "");
|
||||
const expectedWarnings = tryToLoadJson(`test/validator/samples/${dir}/warnings.json`) || [];
|
||||
const expectedErrors = tryToLoadJson(`test/validator/samples/${dir}/errors.json`);
|
||||
const expected_warnings = tryToLoadJson(`test/validator/samples/${dir}/warnings.json`) || [];
|
||||
const expected_errors = tryToLoadJson(`test/validator/samples/${dir}/errors.json`);
|
||||
|
||||
let error;
|
||||
|
||||
try {
|
||||
const warnings = [];
|
||||
|
||||
const { stats } = svelte.compile(input, {
|
||||
onwarn(warning) {
|
||||
const { code, message, pos, start, end } = warning;
|
||||
warnings.push({ code, message, pos, start, end });
|
||||
},
|
||||
dev: config.dev,
|
||||
legacy: config.legacy,
|
||||
generate: false
|
||||
});
|
||||
|
||||
assert.equal(stats.warnings.length, warnings.length);
|
||||
stats.warnings.forEach((full, i) => {
|
||||
const lite = warnings[i];
|
||||
assert.deepEqual({
|
||||
code: full.code,
|
||||
message: full.message,
|
||||
pos: full.pos,
|
||||
start: full.start,
|
||||
end: full.end
|
||||
}, lite);
|
||||
});
|
||||
const warnings = stats.warnings.map(w => ({
|
||||
code: w.code,
|
||||
message: w.message,
|
||||
pos: w.pos,
|
||||
start: w.start,
|
||||
end: w.end
|
||||
}));
|
||||
|
||||
assert.deepEqual(warnings, expectedWarnings);
|
||||
assert.deepEqual(warnings, expected_warnings);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
const expected = expectedErrors && expectedErrors[0];
|
||||
const expected = expected_errors && expected_errors[0];
|
||||
|
||||
if (error || expected) {
|
||||
if (error && !expected) {
|
||||
|
@ -1,3 +0,0 @@
|
||||
export default {
|
||||
dev: true
|
||||
};
|
@ -1,5 +0,0 @@
|
||||
{#each things as thing}
|
||||
|
||||
{/each}
|
||||
|
||||
{#each things as thing}{/each}
|
@ -1 +0,0 @@
|
||||
[]
|
Loading…
Reference in New Issue
Block a user