Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const standardTransform: StandardTransform = function (sourceFile: ts.SourceFile) {
const ops: TransformOperation[] = [];
const entryModule = getResolvedEntryModule(getNgCompiler());
if (!shouldTransform(sourceFile.fileName) || !entryModule) {
return ops;
}
// Find all identifiers.
const entryModuleIdentifiers = collectDeepNodes(sourceFile,
ts.SyntaxKind.Identifier)
.filter(identifier => identifier.text === entryModule.className);
if (entryModuleIdentifiers.length === 0) {
return [];
}
const relativeEntryModulePath = relative(dirname(sourceFile.fileName), entryModule.path);
const normalizedEntryModulePath = `./${relativeEntryModulePath}`.replace(/\\/g, '/');
// Find the bootstrap calls.
entryModuleIdentifiers.forEach(entryModuleIdentifier => {
// Figure out if it's a `platformNativeScriptDynamic().bootstrapModule(AppModule)` call.
if (!(
entryModuleIdentifier.parent
&& entryModuleIdentifier.parent.kind === ts.SyntaxKind.CallExpression
export function handleHmrSupport(
mainFile: ts.SourceFile
): TransformOperation[] {
const importNodesInFile = collectDeepNodes(mainFile, ts.SyntaxKind.ImportDeclaration);
if (!importNodesInFile || !importNodesInFile.length) {
return [];
}
const bootstrapModuleCallNode = findBootstrapModuleCallInSource(mainFile);
if (!bootstrapModuleCallNode || !bootstrapModuleCallNode.arguments || !bootstrapModuleCallNode.arguments.length) {
return [];
}
const appModuleName = getExpressionName(bootstrapModuleCallNode.arguments[0]);
const nativeScriptPlatformCallNode = findNativeScriptPlatformCallInSource(mainFile);
if (!nativeScriptPlatformCallNode || !nativeScriptPlatformCallNode.arguments) {
return [];
}
return handleHmrSupportCore(mainFile, importNodesInFile, appModuleName, nativeScriptPlatformCallNode);