Skip to content

Commit

Permalink
fix(dev-server): fix handling css parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed May 17, 2019
1 parent c32ad5b commit 06333d7
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/dev-server/dev-client/app-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ function appendDiagnostic(win: Window, doc: Document, config: d.DevClientConfig,

const tdNum = doc.createElement('td');
tdNum.className = 'dev-server-diagnostic-blob-num';
tdNum.setAttribute('data-line-number', l.lineNumber + '');
if (l.lineNumber > -1) {
tdNum.setAttribute('data-line-number', l.lineNumber + '');
}
tr.appendChild(tdNum);

const tdCode = doc.createElement('td');
Expand Down
7 changes: 6 additions & 1 deletion src/sys/node/node-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,12 @@ export class NodeLogger implements d.Logger {
return;
}

let msg = `L${l.lineNumber}: `;
let msg = ``;

if (l.lineNumber > -1) {
msg = `L${l.lineNumber}: `;
}

while (msg.length < INDENT.length) {
msg = ' ' + msg;
}
Expand Down
77 changes: 64 additions & 13 deletions src/sys/node/optimize-css-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,72 @@ export async function optimizeCssWorker(inputOpts: d.OptimizeCssInput) {

const processor = postcss(plugins);

const result = await processor.process(inputOpts.css, {
map: null,
from: inputOpts.filePath
});

result.warnings().forEach(warning => {
output.diagnostics.push({
header: `Optimize CSS: ${warning.plugin}`,
messageText: warning.text,
level: 'warn',
type: 'css'
try {
const result = await processor.process(inputOpts.css, {
map: null,
from: inputOpts.filePath
});
});

output.css = result.css;
result.warnings().forEach(warning => {
output.diagnostics.push({
header: `Optimize CSS: ${warning.plugin}`,
messageText: warning.text,
level: 'warn',
type: 'css',
absFilePath: inputOpts.filePath
});
});

output.css = result.css;

} catch (e) {
const diagnostic: d.Diagnostic = {
header: `Optimize CSS`,
messageText: `CSS Error`,
level: `error`,
type: `css`,
absFilePath: inputOpts.filePath
};

if (typeof e.name === 'string') {
diagnostic.header = e.name;
}

if (typeof e.reason === 'string') {
diagnostic.messageText = e.reason;
}

if (typeof e.source === 'string' && typeof e.line === 'number') {
const lines = (e.source as string).replace(/\r/g, '\n').split('\n');

if (lines.length > 0) {
const addLine = (lineNumber: number) => {
const line = lines[lineNumber];
if (typeof line === 'string') {
const printLine: d.PrintLine = {
lineIndex: -1,
lineNumber: -1,
text: line,
errorCharStart: -1,
errorLength: -1
};
diagnostic.lines = diagnostic.lines || [];
diagnostic.lines.push(printLine);
}
};

addLine(e.line - 3);
addLine(e.line - 2);
addLine(e.line - 1);
addLine(e.line);
addLine(e.line + 1);
addLine(e.line + 2);
addLine(e.line + 3);
}
}

output.diagnostics.push(diagnostic);
}

} catch (e) {
catchError(output.diagnostics, e);
Expand Down

0 comments on commit 06333d7

Please sign in to comment.