Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
plugins,
onwarn: handleRollupWarning(diagnostics),
});
const { output } = await rollupBundler.generate({
amd: { id: namespace + '/' + name },
strict: false,
sourcemap: outputConfig.sourcemap,
format,
});
// Rollup produces multiple chunks when a module uses "import()" with a relative import
// path. We need to ensure the compiled module only contains the main chunk.
if (output.length > 1) {
diagnostics.push(
generateCompilerDiagnostic(ModuleResolutionErrors.RELATIVE_DYNAMIC_IMPORT)
);
}
const result = output[0];
code = result.code;
map = result.map;
} catch (e) {
// Rollup may have clobbered error.code with its own data
if (e instanceof CompilerError && (e as any).pluginCode) {
e.code = (e as any).pluginCode;
}
const diagnostic = normalizeToDiagnostic(ModuleResolutionErrors.MODULE_RESOLUTION_ERROR, e);
diagnostic.level = DiagnosticLevel.Fatal;
diagnostics.push(diagnostic);
}
function warnAt(
errorInfo: LWCErrorInfo,
messageArgs?: any[],
location?: parse5.MarkupData.Location
) {
addDiagnostic(
generateCompilerDiagnostic(errorInfo, {
messageArgs,
origin: {
location: normalizeLocation(location),
},
})
);
}
const validateClosingTag = (node: parse5.AST.Default.Element) => {
if (!node.__location) {
return;
}
const { startTag, endTag } = node.__location;
const isVoidElement = VOID_ELEMENT_SET.has(node.tagName);
const missingClosingTag = !!startTag && !endTag;
if (!isVoidElement && missingClosingTag) {
parsingErrors.push(
generateCompilerDiagnostic(ParserDiagnostics.NO_MATCHING_CLOSING_TAGS, {
messageArgs: [node.tagName],
origin: {
location: {
line: startTag.startLine || startTag.line,
column: startTag.startCol || startTag.col,
start: startTag.startOffset,
length: startTag.endOffset - startTag.startOffset,
},
},
})
);
}
};
const onParseError = (err: parse5.Errors.ParsingError) => {
const { code, startLine, startCol, startOffset, endOffset } = err;
parsingErrors.push(
generateCompilerDiagnostic(ParserDiagnostics.INVALID_HTML_SYNTAX, {
messageArgs: [code],
origin: {
location: {
line: startLine,
column: startCol,
start: startOffset,
length: endOffset - startOffset,
},
},
})
);
};
const location = (toLocate as parse5.AST.Default.Element).__location;
if (!location) {
return getLocation(treeAdapter.getParentNode(toLocate));
} else {
return {
line: location.line || location.startLine,
column: location.col || location.startCol,
start: location.startOffset,
length: location.endOffset - location.startOffset,
};
}
};
addDiagnostic(
generateCompilerDiagnostic(errorInfo, {
messageArgs,
origin: {
location: getLocation(node),
},
})
);
}