Skip to content

Commit f1d4ff6

Browse files
committed
remove onwarn option, just use stats.warnings instead
1 parent 8711472 commit f1d4ff6

File tree

5 files changed

+24
-64
lines changed

5 files changed

+24
-64
lines changed

src/Stats.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,18 @@ function collapseTimings(timings) {
2626
}
2727

2828
export default class Stats {
29-
onwarn: (warning: Warning) => void;
30-
3129
startTime: number;
3230
currentTiming: Timing;
3331
currentChildren: Timing[];
3432
timings: Timing[];
3533
stack: Timing[];
3634
warnings: Warning[];
3735

38-
constructor({ onwarn }: {
39-
onwarn: (warning: Warning) => void
40-
}) {
36+
constructor() {
4137
this.startTime = now();
4238
this.stack = [];
4339
this.currentChildren = this.timings = [];
4440

45-
this.onwarn = onwarn;
46-
4741
this.warnings = [];
4842
}
4943

@@ -114,6 +108,5 @@ export default class Stats {
114108

115109
warn(warning) {
116110
this.warnings.push(warning);
117-
this.onwarn(warning);
118111
}
119112
}

src/compile/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,7 @@ function get_name(filename) {
5454
export default function compile(source: string, options: CompileOptions = {}) {
5555
options = assign({ generate: 'dom', dev: false }, options);
5656

57-
const stats = new Stats({
58-
onwarn: options.onwarn
59-
? (warning: Warning) => options.onwarn(warning, default_onwarn)
60-
: default_onwarn
61-
});
57+
const stats = new Stats();
6258

6359
let ast: Ast;
6460

src/interfaces.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ export interface CompileOptions {
6060
css?: boolean;
6161

6262
preserveComments?: boolean | false;
63-
64-
onwarn?: (warning: Warning, default_onwarn?: (warning: Warning) => void) => void;
6563
}
6664

6765
export interface Visitor {

test/css/index.js

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as assert from 'assert';
22
import * as fs from 'fs';
33
import { env, normalizeHtml, svelte } from '../helpers.js';
44

5-
function tryRequire(file) {
5+
function try_require(file) {
66
try {
77
const mod = require(file);
88
return mod.default || mod;
@@ -12,7 +12,7 @@ function tryRequire(file) {
1212
}
1313
}
1414

15-
function normalizeWarning(warning) {
15+
function normalize_warning(warning) {
1616
warning.frame = warning.frame
1717
.replace(/^\n/, '')
1818
.replace(/^\t+/gm, '')
@@ -49,47 +49,30 @@ describe('css', () => {
4949
}
5050

5151
(solo ? it.only : skip ? it.skip : it)(dir, () => {
52-
const config = tryRequire(`./samples/${dir}/_config.js`) || {};
52+
const config = try_require(`./samples/${dir}/_config.js`) || {};
5353
const input = fs
5454
.readFileSync(`test/css/samples/${dir}/input.svelte`, 'utf-8')
5555
.replace(/\s+$/, '');
5656

57-
const expectedWarnings = (config.warnings || []).map(normalizeWarning);
58-
const domWarnings = [];
59-
const ssrWarnings = [];
57+
const expected_warnings = (config.warnings || []).map(normalize_warning);
6058

6159
const dom = svelte.compile(
6260
input,
63-
Object.assign(config, {
64-
format: 'cjs',
65-
onwarn: warning => {
66-
domWarnings.push(warning);
67-
}
68-
})
61+
Object.assign(config, { format: 'cjs' })
6962
);
7063

71-
assert.deepEqual(dom.stats.warnings, domWarnings);
72-
7364
const ssr = svelte.compile(
7465
input,
75-
Object.assign(config, {
76-
format: 'cjs',
77-
generate: 'ssr',
78-
onwarn: warning => {
79-
ssrWarnings.push(warning);
80-
}
81-
})
66+
Object.assign(config, { format: 'cjs', generate: 'ssr' })
8267
);
8368

84-
assert.deepEqual(dom.stats.warnings, domWarnings);
85-
8669
assert.equal(dom.css.code, ssr.css.code);
8770

88-
assert.deepEqual(
89-
domWarnings.map(normalizeWarning),
90-
ssrWarnings.map(normalizeWarning)
91-
);
92-
assert.deepEqual(domWarnings.map(normalizeWarning), expectedWarnings);
71+
const dom_warnings = dom.stats.warnings.map(normalize_warning);
72+
const ssr_warnings = ssr.stats.warnings.map(normalize_warning);
73+
74+
assert.deepEqual(dom_warnings, ssr_warnings);
75+
assert.deepEqual(dom_warnings.map(normalize_warning), expected_warnings);
9376

9477
fs.writeFileSync(`test/css/samples/${dir}/_actual.css`, dom.css.code);
9578
const expected = {

test/validator/index.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,32 @@ describe("validate", () => {
1818
const config = loadConfig(`./validator/samples/${dir}/_config.js`);
1919

2020
const input = fs.readFileSync(`test/validator/samples/${dir}/input.svelte`, "utf-8").replace(/\s+$/, "");
21-
const expectedWarnings = tryToLoadJson(`test/validator/samples/${dir}/warnings.json`) || [];
22-
const expectedErrors = tryToLoadJson(`test/validator/samples/${dir}/errors.json`);
21+
const expected_warnings = tryToLoadJson(`test/validator/samples/${dir}/warnings.json`) || [];
22+
const expected_errors = tryToLoadJson(`test/validator/samples/${dir}/errors.json`);
2323

2424
let error;
2525

2626
try {
27-
const warnings = [];
28-
2927
const { stats } = svelte.compile(input, {
30-
onwarn(warning) {
31-
const { code, message, pos, start, end } = warning;
32-
warnings.push({ code, message, pos, start, end });
33-
},
3428
dev: config.dev,
3529
legacy: config.legacy,
3630
generate: false
3731
});
3832

39-
assert.equal(stats.warnings.length, warnings.length);
40-
stats.warnings.forEach((full, i) => {
41-
const lite = warnings[i];
42-
assert.deepEqual({
43-
code: full.code,
44-
message: full.message,
45-
pos: full.pos,
46-
start: full.start,
47-
end: full.end
48-
}, lite);
49-
});
33+
const warnings = stats.warnings.map(w => ({
34+
code: w.code,
35+
message: w.message,
36+
pos: w.pos,
37+
start: w.start,
38+
end: w.end
39+
}));
5040

51-
assert.deepEqual(warnings, expectedWarnings);
41+
assert.deepEqual(warnings, expected_warnings);
5242
} catch (e) {
5343
error = e;
5444
}
5545

56-
const expected = expectedErrors && expectedErrors[0];
46+
const expected = expected_errors && expected_errors[0];
5747

5848
if (error || expected) {
5949
if (error && !expected) {

0 commit comments

Comments
 (0)