How to use the @ngtools/webpack/src/transformers.collectDeepNodes function in @ngtools/webpack

To help you get started, we’ve selected a few @ngtools/webpack examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NativeScript / nativescript-dev-webpack / transformers / ns-replace-bootstrap.ts View on Github external
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
github NativeScript / nativescript-dev-webpack / transformers / ns-support-hmr-ng.ts View on Github external
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);