include warnings in stats object

pull/1299/head
Rich-Harris 6 years ago
parent a5d5a6c952
commit c0287f2080

@ -1,4 +1,4 @@
import { Node } from './interfaces';
import { Node, Warning } from './interfaces';
import Generator from './generators/Generator';
const now = (typeof process !== 'undefined' && process.hrtime)
@ -31,11 +31,14 @@ export default class Stats {
currentChildren: Timing[];
timings: Timing[];
stack: Timing[];
warnings: Warning[];
constructor() {
this.startTime = now();
this.stack = [];
this.currentChildren = this.timings = [];
this.warnings = [];
}
start(label) {
@ -91,7 +94,7 @@ export default class Stats {
return {
timings,
warnings: [], // TODO
warnings: this.warnings,
imports,
hooks
};

@ -126,6 +126,14 @@ export function compile(source: string, _options: CompileOptions) {
stats.stop('stylesheet');
stats.start('validate');
// TODO remove this when we remove svelte.validate from public API — we
// can use the stats object instead
const onwarn = options.onwarn;
options.onwarn = warning => {
stats.warnings.push(warning);
onwarn(warning);
};
validate(parsed, source, stylesheet, options);
stats.stop('validate');

@ -3,6 +3,7 @@ import validateHtml from './html/index';
import { getLocator, Location } from 'locate-character';
import getCodeFrame from '../utils/getCodeFrame';
import CompileError from '../utils/CompileError';
import Stats from '../Stats';
import Stylesheet from '../css/Stylesheet';
import { Node, Parsed, CompileOptions, Warning } from '../interfaces';

@ -26,7 +26,7 @@ describe("validate", () => {
try {
const warnings = [];
svelte.compile(input, {
const { stats } = svelte.compile(input, {
onwarn(warning) {
warnings.push({
message: warning.message,
@ -38,6 +38,17 @@ describe("validate", () => {
dev: config.dev
});
assert.equal(stats.warnings.length, warnings.length);
stats.warnings.forEach((full, i) => {
const lite = warnings[i];
assert.deepEqual({
message: full.message,
pos: full.pos,
loc: full.loc,
end: full.end
}, lite);
});
assert.deepEqual(warnings, expectedWarnings);
} catch (e) {
error = e;

Loading…
Cancel
Save