diff --git a/tools/symbol-extractor/cli.ts b/tools/symbol-extractor/cli.ts index 6426485044..383c19ff71 100644 --- a/tools/symbol-extractor/cli.ts +++ b/tools/symbol-extractor/cli.ts @@ -40,9 +40,11 @@ function main(argv: [string, string, string] | [string, string]): boolean { } else { passed = symbolExtractor.compareAndPrintError(goldenFilePath, goldenContent); if (!passed) { + const compile = process.env['compile']; + const defineFlag = (compile !== 'legacy') ? `--define=compile=${compile} ` : ''; console.error(`TEST FAILED!`); console.error(` To update the golden file run: `); - console.error(` bazel run ${process.env['BAZEL_TARGET']}.accept`); + console.error(` bazel run ${defineFlag}${process.env['BAZEL_TARGET']}.accept`); } } return passed; diff --git a/tools/symbol-extractor/symbol_extractor.ts b/tools/symbol-extractor/symbol_extractor.ts index 8dc964a517..ed34816472 100644 --- a/tools/symbol-extractor/symbol_extractor.ts +++ b/tools/symbol-extractor/symbol_extractor.ts @@ -49,8 +49,7 @@ export class SymbolExtractor { if (varDecl.initializer && fnRecurseDepth !== 0) { symbols.push({name: varDecl.name.getText()}); } - if (fnRecurseDepth == 0 && - isRollupExportSymbol(child.parent as ts.VariableDeclarationList)) { + if (fnRecurseDepth == 0 && isRollupExportSymbol(varDecl)) { ts.forEachChild(child, visitor); } break; @@ -122,13 +121,12 @@ function toName(symbol: Symbol): string { } /** - * Detects if VariableDeclarationList is format `var x = function(){}()`; + * Detects if VariableDeclarationList is format `var ..., bundle = function(){}()`; * * Rollup produces this format when it wants to export symbols from a bundle. * @param child */ -function isRollupExportSymbol(child: ts.VariableDeclarationList): boolean { - if (child.declarations.length !== 1) return false; - const decl: ts.VariableDeclaration = child.declarations[0]; - return !!(decl.initializer && decl.initializer.kind == ts.SyntaxKind.CallExpression); +function isRollupExportSymbol(decl: ts.VariableDeclaration): boolean { + return !!(decl.initializer && decl.initializer.kind == ts.SyntaxKind.CallExpression) && + ts.isIdentifier(decl.name) && decl.name.text === 'bundle'; } \ No newline at end of file diff --git a/tools/symbol-extractor/symbol_extractor_spec/iife_with_export.js b/tools/symbol-extractor/symbol_extractor_spec/iife_with_export.js index 2881163809..41df5cabeb 100644 --- a/tools/symbol-extractor/symbol_extractor_spec/iife_with_export.js +++ b/tools/symbol-extractor/symbol_extractor_spec/iife_with_export.js @@ -10,7 +10,7 @@ * Rollup exports symbols in this particular way. This test demonstrates that we can correctly read * symbols. */ -var fooBar = function(exports) { +var bundle = function(exports) { 'use strict'; // tslint:disable-next-line:no-console console.log('Hello, Alice in Wonderland');