From 6a9a48b0ac05cb467edc23a4933672a87b90a21d Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Sat, 12 Jan 2019 00:59:48 -0800 Subject: [PATCH] test: improve symbol-extractor test by ignoring $1 suffix (#28098) PR Close #28098 --- packages/common/src/directives/ng_for_of.ts | 6 +-- packages/core/src/render3/component.ts | 4 +- packages/core/src/render3/di.ts | 8 ++-- packages/core/src/render3/discovery_utils.ts | 4 +- packages/core/src/render3/i18n.ts | 4 +- packages/core/src/render3/instructions.ts | 45 ++++++++++--------- packages/core/src/render3/jit/directive.ts | 10 ++--- packages/core/src/render3/jit/module.ts | 16 +++---- packages/core/src/render3/jit/pipe.ts | 4 +- .../core/src/render3/node_manipulation.ts | 6 +-- packages/core/src/render3/util.ts | 5 ++- .../core/src/sanitization/sanitization.ts | 8 ++-- .../hello_world/bundle.golden_symbols.json | 6 +-- .../injection/bundle.golden_symbols.json | 10 ++--- .../bundling/todo/bundle.golden_symbols.json | 16 +++---- tools/symbol-extractor/symbol_extractor.ts | 9 +++- .../drop_trailing_suffix.js | 12 +++++ .../drop_trailing_suffix.json | 5 +++ .../hello_world_min_debug.json | 15 ++++--- 19 files changed, 111 insertions(+), 82 deletions(-) create mode 100644 tools/symbol-extractor/symbol_extractor_spec/drop_trailing_suffix.js create mode 100644 tools/symbol-extractor/symbol_extractor_spec/drop_trailing_suffix.json diff --git a/packages/common/src/directives/ng_for_of.ts b/packages/common/src/directives/ng_for_of.ts index f916f7f156..d9aaf9c4b1 100644 --- a/packages/common/src/directives/ng_for_of.ts +++ b/packages/common/src/directives/ng_for_of.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ -import {ChangeDetectorRef, Directive, DoCheck, EmbeddedViewRef, Input, IterableChangeRecord, IterableChanges, IterableDiffer, IterableDiffers, NgIterable, TemplateRef, TrackByFunction, ViewContainerRef, forwardRef, isDevMode} from '@angular/core'; +import {Directive, DoCheck, EmbeddedViewRef, Input, IterableChangeRecord, IterableChanges, IterableDiffer, IterableDiffers, NgIterable, TemplateRef, TrackByFunction, ViewContainerRef, forwardRef, isDevMode} from '@angular/core'; /** * @publicApi @@ -151,7 +151,7 @@ export class NgForOf implements DoCheck { this._differ = this._differs.find(value).create(this.ngForTrackBy); } catch { throw new Error( - `Cannot find a differ supporting object '${value}' of type '${getTypeNameForDebugging(value)}'. NgFor only supports binding to Iterables such as Arrays.`); + `Cannot find a differ supporting object '${value}' of type '${getTypeName(value)}'. NgFor only supports binding to Iterables such as Arrays.`); } } } @@ -218,6 +218,6 @@ class RecordViewTuple { constructor(public record: any, public view: EmbeddedViewRef>) {} } -export function getTypeNameForDebugging(type: any): string { +function getTypeName(type: any): string { return type['name'] || typeof type; } diff --git a/packages/core/src/render3/component.ts b/packages/core/src/render3/component.ts index e932734c71..0bc8cbaff3 100644 --- a/packages/core/src/render3/component.ts +++ b/packages/core/src/render3/component.ts @@ -25,7 +25,7 @@ import {PlayerHandler} from './interfaces/player'; import {RElement, Renderer3, RendererFactory3, domRendererFactory3} from './interfaces/renderer'; import {CONTEXT, FLAGS, HEADER_OFFSET, HOST, HOST_NODE, LView, LViewFlags, RootContext, RootContextFlags, TVIEW} from './interfaces/view'; import {enterView, getPreviousOrParentTNode, leaveView, resetComponentState, setCurrentDirectiveDef} from './state'; -import {defaultScheduler, getRootView, readPatchedLView, stringify} from './util'; +import {defaultScheduler, getRootView, readPatchedLView, renderStringify} from './util'; @@ -84,7 +84,7 @@ type HostFeature = ((component: T, componentDef: ComponentDef) => void); // TODO: A hack to not pull in the NullInjector from @angular/core. export const NULL_INJECTOR: Injector = { get: (token: any, notFoundValue?: any) => { - throw new Error('NullInjector: Not found: ' + stringify(token)); + throw new Error('NullInjector: Not found: ' + renderStringify(token)); } }; diff --git a/packages/core/src/render3/di.ts b/packages/core/src/render3/di.ts index 6164fd06a5..c49956353c 100644 --- a/packages/core/src/render3/di.ts +++ b/packages/core/src/render3/di.ts @@ -22,7 +22,7 @@ import {DECLARATION_VIEW, HOST_NODE, INJECTOR, LView, TData, TVIEW, TView} from import {assertNodeOfPossibleTypes} from './node_assert'; import {unwrapOnChangesDirectiveWrapper} from './onchanges_util'; import {getLView, getPreviousOrParentTNode, setTNodeAndViewData} from './state'; -import {findComponentView, getParentInjectorIndex, getParentInjectorView, hasParentInjector, isComponent, isComponentDef, stringify} from './util'; +import {findComponentView, getParentInjectorIndex, getParentInjectorView, hasParentInjector, isComponent, isComponentDef, renderStringify} from './util'; @@ -312,7 +312,7 @@ export function getOrCreateInjectable( try { const value = bloomHash(); if (value == null && !(flags & InjectFlags.Optional)) { - throw new Error(`No provider for ${stringify(token)}!`); + throw new Error(`No provider for ${renderStringify(token)}!`); } else { return value; } @@ -402,7 +402,7 @@ export function getOrCreateInjectable( if (flags & InjectFlags.Optional) { return notFoundValue; } else { - throw new Error(`NodeInjector: NOT_FOUND [${stringify(token)}]`); + throw new Error(`NodeInjector: NOT_FOUND [${renderStringify(token)}]`); } } @@ -500,7 +500,7 @@ export function getNodeInjectable( if (isFactory(value)) { const factory: NodeInjectorFactory = value; if (factory.resolving) { - throw new Error(`Circular dep for ${stringify(tData[index])}`); + throw new Error(`Circular dep for ${renderStringify(tData[index])}`); } const previousIncludeViewProviders = setIncludeViewProviders(factory.canSeeViewProviders); factory.resolving = true; diff --git a/packages/core/src/render3/discovery_utils.ts b/packages/core/src/render3/discovery_utils.ts index e58eb0ef84..31701cd30c 100644 --- a/packages/core/src/render3/discovery_utils.ts +++ b/packages/core/src/render3/discovery_utils.ts @@ -15,7 +15,7 @@ import {LContext} from './interfaces/context'; import {DirectiveDef} from './interfaces/definition'; import {TElementNode, TNode, TNodeProviderIndexes} from './interfaces/node'; import {CLEANUP, CONTEXT, FLAGS, HOST, LView, LViewFlags, PARENT, RootContext, TVIEW} from './interfaces/view'; -import {readElementValue, readPatchedLView, stringify} from './util'; +import {readElementValue, readPatchedLView, renderStringify} from './util'; @@ -201,7 +201,7 @@ export function loadLContext(target: {}, throwOnNotFound: boolean = true): LCont const context = getLContext(target); if (!context && throwOnNotFound) { throw new Error( - ngDevMode ? `Unable to find context associated with ${stringify(target)}` : + ngDevMode ? `Unable to find context associated with ${renderStringify(target)}` : 'Invalid ng target'); } return context; diff --git a/packages/core/src/render3/i18n.ts b/packages/core/src/render3/i18n.ts index 4d62e76c99..453498d1f4 100644 --- a/packages/core/src/render3/i18n.ts +++ b/packages/core/src/render3/i18n.ts @@ -22,7 +22,7 @@ import {BINDING_INDEX, HEADER_OFFSET, HOST_NODE, LView, RENDERER, TVIEW, TView} import {appendChild, createTextNode, removeChild} from './node_manipulation'; import {getIsParent, getLView, getPreviousOrParentTNode, setIsParent, setPreviousOrParentTNode} from './state'; import {NO_CHANGE} from './tokens'; -import {addAllToArray, getNativeByIndex, getNativeByTNode, getTNode, isLContainer, stringify} from './util'; +import {addAllToArray, getNativeByIndex, getNativeByTNode, getTNode, isLContainer, renderStringify} from './util'; const MARKER = `�`; const ICU_BLOCK_REGEX = /^\s*(�\d+:?\d*�)\s*,\s*(select|plural)\s*,/; @@ -712,7 +712,7 @@ function readUpdateOpCodes( } else if (typeof opCode == 'number') { if (opCode < 0) { // It's a binding index whose value is negative - value += stringify(viewData[bindingsStartIndex - opCode]); + value += renderStringify(viewData[bindingsStartIndex - opCode]); } else { const nodeIndex = opCode >>> I18nUpdateOpCode.SHIFT_REF; switch (opCode & I18nUpdateOpCode.MASK_OPCODE) { diff --git a/packages/core/src/render3/instructions.ts b/packages/core/src/render3/instructions.ts index ee54f486d1..d37441a510 100644 --- a/packages/core/src/render3/instructions.ts +++ b/packages/core/src/render3/instructions.ts @@ -40,7 +40,7 @@ import {getInitialClassNameValue, initializeStaticContext as initializeStaticSty import {BoundPlayerFactory} from './styling/player_factory'; import {createEmptyStylingContext, getStylingContext, hasClassInput, hasStyling, isAnimationProp} from './styling/util'; import {NO_CHANGE} from './tokens'; -import {findComponentView, getComponentViewByIndex, getNativeByIndex, getNativeByTNode, getRootContext, getRootView, getTNode, isComponent, isComponentDef, loadInternal, readElementValue, readPatchedLView, stringify} from './util'; +import {findComponentView, getComponentViewByIndex, getNativeByIndex, getNativeByTNode, getRootContext, getRootView, getTNode, isComponent, isComponentDef, loadInternal, readElementValue, readPatchedLView, renderStringify} from './util'; @@ -788,7 +788,7 @@ function setUpAttributes(native: RElement, attrs: TAttributes): void { } export function createError(text: string, token: any) { - return new Error(`Renderer: ${text} [${stringify(token)}]`); + return new Error(`Renderer: ${text} [${renderStringify(token)}]`); } @@ -984,7 +984,7 @@ export function elementAttribute( ngDevMode && ngDevMode.rendererSetAttribute++; const tNode = getTNode(index, lView); const strValue = - sanitizer == null ? stringify(value) : sanitizer(value, tNode.tagName || '', name); + sanitizer == null ? renderStringify(value) : sanitizer(value, tNode.tagName || '', name); isProceduralRenderer(renderer) ? renderer.setAttribute(element, name, strValue) : element.setAttribute(name, strValue); } @@ -1329,7 +1329,7 @@ export function elementStyleProp( if (suffix) { // when a suffix is applied then it will bypass // sanitization entirely (b/c a new string is created) - valueToAdd = stringify(value) + suffix; + valueToAdd = renderStringify(value) + suffix; } else { // sanitization happens by dealing with a String value // this means that the string value will be passed through @@ -1458,8 +1458,8 @@ export function textBinding(index: number, value: T | NO_CHANGE): void { ngDevMode && assertDefined(element, 'native element should exist'); ngDevMode && ngDevMode.rendererSetText++; const renderer = lView[RENDERER]; - isProceduralRenderer(renderer) ? renderer.setValue(element, stringify(value)) : - element.textContent = stringify(value); + isProceduralRenderer(renderer) ? renderer.setValue(element, renderStringify(value)) : + element.textContent = renderStringify(value); } } @@ -2718,7 +2718,7 @@ export function interpolationV(values: any[]): string|NO_CHANGE { // Build the updated content let content = values[0]; for (let i = 1; i < values.length; i += 2) { - content += stringify(values[i]) + values[i + 1]; + content += renderStringify(values[i]) + values[i + 1]; } return content; @@ -2735,7 +2735,7 @@ export function interpolation1(prefix: string, v0: any, suffix: string): string| const lView = getLView(); const different = bindingUpdated(lView, lView[BINDING_INDEX], v0); lView[BINDING_INDEX] += 1; - return different ? prefix + stringify(v0) + suffix : NO_CHANGE; + return different ? prefix + renderStringify(v0) + suffix : NO_CHANGE; } /** Creates an interpolation binding with 2 expressions. */ @@ -2745,7 +2745,7 @@ export function interpolation2( const different = bindingUpdated2(lView, lView[BINDING_INDEX], v0, v1); lView[BINDING_INDEX] += 2; - return different ? prefix + stringify(v0) + i0 + stringify(v1) + suffix : NO_CHANGE; + return different ? prefix + renderStringify(v0) + i0 + renderStringify(v1) + suffix : NO_CHANGE; } /** Creates an interpolation binding with 3 expressions. */ @@ -2756,8 +2756,9 @@ export function interpolation3( const different = bindingUpdated3(lView, lView[BINDING_INDEX], v0, v1, v2); lView[BINDING_INDEX] += 3; - return different ? prefix + stringify(v0) + i0 + stringify(v1) + i1 + stringify(v2) + suffix : - NO_CHANGE; + return different ? + prefix + renderStringify(v0) + i0 + renderStringify(v1) + i1 + renderStringify(v2) + suffix : + NO_CHANGE; } /** Create an interpolation binding with 4 expressions. */ @@ -2769,8 +2770,8 @@ export function interpolation4( lView[BINDING_INDEX] += 4; return different ? - prefix + stringify(v0) + i0 + stringify(v1) + i1 + stringify(v2) + i2 + stringify(v3) + - suffix : + prefix + renderStringify(v0) + i0 + renderStringify(v1) + i1 + renderStringify(v2) + i2 + + renderStringify(v3) + suffix : NO_CHANGE; } @@ -2785,8 +2786,8 @@ export function interpolation5( lView[BINDING_INDEX] += 5; return different ? - prefix + stringify(v0) + i0 + stringify(v1) + i1 + stringify(v2) + i2 + stringify(v3) + i3 + - stringify(v4) + suffix : + prefix + renderStringify(v0) + i0 + renderStringify(v1) + i1 + renderStringify(v2) + i2 + + renderStringify(v3) + i3 + renderStringify(v4) + suffix : NO_CHANGE; } @@ -2801,8 +2802,8 @@ export function interpolation6( lView[BINDING_INDEX] += 6; return different ? - prefix + stringify(v0) + i0 + stringify(v1) + i1 + stringify(v2) + i2 + stringify(v3) + i3 + - stringify(v4) + i4 + stringify(v5) + suffix : + prefix + renderStringify(v0) + i0 + renderStringify(v1) + i1 + renderStringify(v2) + i2 + + renderStringify(v3) + i3 + renderStringify(v4) + i4 + renderStringify(v5) + suffix : NO_CHANGE; } @@ -2818,8 +2819,9 @@ export function interpolation7( lView[BINDING_INDEX] += 7; return different ? - prefix + stringify(v0) + i0 + stringify(v1) + i1 + stringify(v2) + i2 + stringify(v3) + i3 + - stringify(v4) + i4 + stringify(v5) + i5 + stringify(v6) + suffix : + prefix + renderStringify(v0) + i0 + renderStringify(v1) + i1 + renderStringify(v2) + i2 + + renderStringify(v3) + i3 + renderStringify(v4) + i4 + renderStringify(v5) + i5 + + renderStringify(v6) + suffix : NO_CHANGE; } @@ -2835,8 +2837,9 @@ export function interpolation8( lView[BINDING_INDEX] += 8; return different ? - prefix + stringify(v0) + i0 + stringify(v1) + i1 + stringify(v2) + i2 + stringify(v3) + i3 + - stringify(v4) + i4 + stringify(v5) + i5 + stringify(v6) + i6 + stringify(v7) + suffix : + prefix + renderStringify(v0) + i0 + renderStringify(v1) + i1 + renderStringify(v2) + i2 + + renderStringify(v3) + i3 + renderStringify(v4) + i4 + renderStringify(v5) + i5 + + renderStringify(v6) + i6 + renderStringify(v7) + suffix : NO_CHANGE; } diff --git a/packages/core/src/render3/jit/directive.ts b/packages/core/src/render3/jit/directive.ts index 2bc3cbb967..31cfa009ab 100644 --- a/packages/core/src/render3/jit/directive.ts +++ b/packages/core/src/render3/jit/directive.ts @@ -15,7 +15,7 @@ import {componentNeedsResolution, maybeQueueResolutionOfComponentResources} from import {ViewEncapsulation} from '../../metadata/view'; import {EMPTY_ARRAY, EMPTY_OBJ} from '../empty'; import {NG_COMPONENT_DEF, NG_DIRECTIVE_DEF} from '../fields'; -import {stringify} from '../util'; +import {renderStringify} from '../util'; import {R3DirectiveMetadataFacade, getCompilerFacade} from './compiler_facade'; import {R3ComponentMetadataFacade, R3QueryMetadataFacade} from './compiler_facade_interface'; @@ -43,9 +43,9 @@ export function compileComponent(type: Type, metadata: Component): void { const compiler = getCompilerFacade(); if (ngComponentDef === null) { if (componentNeedsResolution(metadata)) { - const error = [`Component '${stringify(type)}' is not resolved:`]; + const error = [`Component '${renderStringify(type)}' is not resolved:`]; if (metadata.templateUrl) { - error.push(` - templateUrl: ${stringify(metadata.templateUrl)}`); + error.push(` - templateUrl: ${renderStringify(metadata.templateUrl)}`); } if (metadata.styleUrls && metadata.styleUrls.length) { error.push(` - styleUrls: ${JSON.stringify(metadata.styleUrls)}`); @@ -69,7 +69,7 @@ export function compileComponent(type: Type, metadata: Component): void { viewProviders: metadata.viewProviders || null, }; ngComponentDef = compiler.compileComponent( - angularCoreEnv, `ng://${stringify(type)}/template.html`, meta); + angularCoreEnv, `ng://${renderStringify(type)}/template.html`, meta); // When NgModule decorator executed, we enqueued the module definition such that // it would only dequeue and add itself as module scope to all of its declarations, @@ -176,7 +176,7 @@ function extractQueriesMetadata( if (!ann.selector) { throw new Error( `Can't construct a query for the property "${field}" of ` + - `"${stringify(type)}" since the query selector wasn't defined.`); + `"${renderStringify(type)}" since the query selector wasn't defined.`); } queriesMeta.push(convertToR3QueryMetadata(field, ann)); } diff --git a/packages/core/src/render3/jit/module.ts b/packages/core/src/render3/jit/module.ts index 98c37b64f7..ca2dffd656 100644 --- a/packages/core/src/render3/jit/module.ts +++ b/packages/core/src/render3/jit/module.ts @@ -17,7 +17,7 @@ import {getComponentDef, getDirectiveDef, getNgModuleDef, getPipeDef} from '../d import {NG_COMPONENT_DEF, NG_DIRECTIVE_DEF, NG_MODULE_DEF, NG_PIPE_DEF} from '../fields'; import {ComponentDef} from '../interfaces/definition'; import {NgModuleType} from '../ng_module_ref'; -import {stringify} from '../util'; +import {renderStringify} from '../util'; import {R3InjectorMetadataFacade, getCompilerFacade} from './compiler_facade'; import {angularCoreEnv} from './environment'; @@ -183,7 +183,7 @@ function verifySemanticsOfNgModuleDef(moduleType: NgModuleType): void { const def = getComponentDef(type) || getDirectiveDef(type) || getPipeDef(type); if (!def) { errors.push( - `Unexpected value '${stringify(type)}' declared by the module '${stringify(moduleType)}'. Please add a @Pipe/@Directive/@Component annotation.`); + `Unexpected value '${renderStringify(type)}' declared by the module '${renderStringify(moduleType)}'. Please add a @Pipe/@Directive/@Component annotation.`); } } @@ -197,7 +197,7 @@ function verifySemanticsOfNgModuleDef(moduleType: NgModuleType): void { if (combinedDeclarations.lastIndexOf(type) === -1) { // We are exporting something which we don't explicitly declare or import. errors.push( - `Can't export ${kind} ${stringify(type)} from ${stringify(moduleType)} as it was neither declared nor imported!`); + `Can't export ${kind} ${renderStringify(type)} from ${renderStringify(moduleType)} as it was neither declared nor imported!`); } } } @@ -206,11 +206,11 @@ function verifySemanticsOfNgModuleDef(moduleType: NgModuleType): void { type = resolveForwardRef(type); const existingModule = ownerNgModule.get(type); if (existingModule && existingModule !== moduleType) { - const modules = [existingModule, moduleType].map(stringify).sort(); + const modules = [existingModule, moduleType].map(renderStringify).sort(); errors.push( - `Type ${stringify(type)} is part of the declarations of 2 modules: ${modules[0]} and ${modules[1]}! ` + - `Please consider moving ${stringify(type)} to a higher module that imports ${modules[0]} and ${modules[1]}. ` + - `You can also create a new NgModule that exports and includes ${stringify(type)} then import that NgModule in ${modules[0]} and ${modules[1]}.`); + `Type ${renderStringify(type)} is part of the declarations of 2 modules: ${modules[0]} and ${modules[1]}! ` + + `Please consider moving ${renderStringify(type)} to a higher module that imports ${modules[0]} and ${modules[1]}. ` + + `You can also create a new NgModule that exports and includes ${renderStringify(type)} then import that NgModule in ${modules[0]} and ${modules[1]}.`); } else { // Mark type as having owner. ownerNgModule.set(type, moduleType); @@ -222,7 +222,7 @@ function verifySemanticsOfNgModuleDef(moduleType: NgModuleType): void { const existingModule = ownerNgModule.get(type); if (!existingModule) { errors.push( - `Component ${stringify(type)} is not part of any NgModule or the module has not been imported into your module.`); + `Component ${renderStringify(type)} is not part of any NgModule or the module has not been imported into your module.`); } } diff --git a/packages/core/src/render3/jit/pipe.ts b/packages/core/src/render3/jit/pipe.ts index a03f565db9..84c4764817 100644 --- a/packages/core/src/render3/jit/pipe.ts +++ b/packages/core/src/render3/jit/pipe.ts @@ -9,7 +9,7 @@ import {Type} from '../../interface/type'; import {Pipe} from '../../metadata/directives'; import {NG_PIPE_DEF} from '../fields'; -import {stringify} from '../util'; +import {renderStringify} from '../util'; import {getCompilerFacade} from './compiler_facade'; import {angularCoreEnv} from './environment'; @@ -21,7 +21,7 @@ export function compilePipe(type: Type, meta: Pipe): void { get: () => { if (ngPipeDef === null) { ngPipeDef = getCompilerFacade().compilePipe( - angularCoreEnv, `ng://${stringify(type)}/ngPipeDef.js`, { + angularCoreEnv, `ng://${renderStringify(type)}/ngPipeDef.js`, { type: type, name: type.name, deps: reflectDependencies(type), diff --git a/packages/core/src/render3/node_manipulation.ts b/packages/core/src/render3/node_manipulation.ts index 741961b52f..f96f6e0638 100644 --- a/packages/core/src/render3/node_manipulation.ts +++ b/packages/core/src/render3/node_manipulation.ts @@ -14,7 +14,7 @@ import {unusedValueExportToPlacateAjd as unused3} from './interfaces/projection' import {ProceduralRenderer3, RComment, RElement, RNode, RText, Renderer3, isProceduralRenderer, unusedValueExportToPlacateAjd as unused4} from './interfaces/renderer'; import {CLEANUP, CONTAINER_INDEX, FLAGS, HEADER_OFFSET, HOST_NODE, HookData, LView, LViewFlags, NEXT, PARENT, QUERIES, RENDERER, TVIEW, unusedValueExportToPlacateAjd as unused5} from './interfaces/view'; import {assertNodeType} from './node_assert'; -import {findComponentView, getNativeByTNode, isLContainer, isRootView, readElementValue, stringify} from './util'; +import {findComponentView, getNativeByTNode, isLContainer, isRootView, readElementValue, renderStringify} from './util'; const unusedValueToPlacateAjd = unused1 + unused2 + unused3 + unused4 + unused5; @@ -178,8 +178,8 @@ function executeNodeAction( } export function createTextNode(value: any, renderer: Renderer3): RText { - return isProceduralRenderer(renderer) ? renderer.createText(stringify(value)) : - renderer.createTextNode(stringify(value)); + return isProceduralRenderer(renderer) ? renderer.createText(renderStringify(value)) : + renderer.createTextNode(renderStringify(value)); } /** diff --git a/packages/core/src/render3/util.ts b/packages/core/src/render3/util.ts index 77c5c5bb41..31d03f94dc 100644 --- a/packages/core/src/render3/util.ts +++ b/packages/core/src/render3/util.ts @@ -31,7 +31,10 @@ export function isDifferent(a: any, b: any): boolean { return !(a !== a && b !== b) && a !== b; } -export function stringify(value: any): string { +/** + * Used for stringify render output in Ivy. + */ +export function renderStringify(value: any): string { if (typeof value == 'function') return value.name || value; if (typeof value == 'string') return value; if (value == null) return ''; diff --git a/packages/core/src/sanitization/sanitization.ts b/packages/core/src/sanitization/sanitization.ts index 969db77592..9b92fb35e3 100644 --- a/packages/core/src/sanitization/sanitization.ts +++ b/packages/core/src/sanitization/sanitization.ts @@ -8,7 +8,7 @@ import {SANITIZER} from '../render3/interfaces/view'; import {getLView} from '../render3/state'; -import {stringify} from '../render3/util'; +import {renderStringify} from '../render3/util'; import {BypassType, allowSanitizationBypass} from './bypass'; import {_sanitizeHtml as _sanitizeHtml} from './html_sanitizer'; @@ -39,7 +39,7 @@ export function sanitizeHtml(unsafeHtml: any): string { if (allowSanitizationBypass(unsafeHtml, BypassType.Html)) { return unsafeHtml.toString(); } - return _sanitizeHtml(document, stringify(unsafeHtml)); + return _sanitizeHtml(document, renderStringify(unsafeHtml)); } /** @@ -63,7 +63,7 @@ export function sanitizeStyle(unsafeStyle: any): string { if (allowSanitizationBypass(unsafeStyle, BypassType.Style)) { return unsafeStyle.toString(); } - return _sanitizeStyle(stringify(unsafeStyle)); + return _sanitizeStyle(renderStringify(unsafeStyle)); } /** @@ -88,7 +88,7 @@ export function sanitizeUrl(unsafeUrl: any): string { if (allowSanitizationBypass(unsafeUrl, BypassType.Url)) { return unsafeUrl.toString(); } - return _sanitizeUrl(stringify(unsafeUrl)); + return _sanitizeUrl(renderStringify(unsafeUrl)); } /** diff --git a/packages/core/test/bundling/hello_world/bundle.golden_symbols.json b/packages/core/test/bundling/hello_world/bundle.golden_symbols.json index e1caf4b8fb..47d6132932 100644 --- a/packages/core/test/bundling/hello_world/bundle.golden_symbols.json +++ b/packages/core/test/bundling/hello_world/bundle.golden_symbols.json @@ -401,6 +401,9 @@ { "name": "renderEmbeddedTemplate" }, + { + "name": "renderStringify" + }, { "name": "resetComponentState" }, @@ -434,9 +437,6 @@ { "name": "setUpAttributes" }, - { - "name": "stringify$1" - }, { "name": "syncViewWithBlueprint" }, diff --git a/packages/core/test/bundling/injection/bundle.golden_symbols.json b/packages/core/test/bundling/injection/bundle.golden_symbols.json index 8f438c3f98..33e1162f8f 100644 --- a/packages/core/test/bundling/injection/bundle.golden_symbols.json +++ b/packages/core/test/bundling/injection/bundle.golden_symbols.json @@ -3,16 +3,16 @@ "name": "APP_ROOT" }, { - "name": "CIRCULAR$1" + "name": "CIRCULAR" }, { - "name": "EMPTY_ARRAY$2" + "name": "EMPTY_ARRAY" }, { "name": "EmptyErrorImpl" }, { - "name": "INJECTOR$1" + "name": "INJECTOR" }, { "name": "Inject" @@ -33,7 +33,7 @@ "name": "NOT_YET" }, { - "name": "NULL_INJECTOR$1" + "name": "NULL_INJECTOR" }, { "name": "NullInjector" @@ -63,7 +63,7 @@ "name": "THROW_IF_NOT_FOUND" }, { - "name": "USE_VALUE$2" + "name": "USE_VALUE" }, { "name": "UnsubscriptionErrorImpl" diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index 328fce36ab..b4c3aabbfb 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -795,10 +795,10 @@ "name": "getTViewCleanup" }, { - "name": "getTypeNameForDebugging" + "name": "getTypeName" }, { - "name": "getTypeNameForDebugging$1" + "name": "getTypeNameForDebugging" }, { "name": "getValue" @@ -906,13 +906,13 @@ "name": "isFactory" }, { - "name": "isJsObject$1" + "name": "isJsObject" }, { "name": "isLContainer" }, { - "name": "isListLikeIterable$1" + "name": "isListLikeIterable" }, { "name": "isNodeMatchingSelector" @@ -936,7 +936,7 @@ "name": "isStylingContext" }, { - "name": "iterateListLike$1" + "name": "iterateListLike" }, { "name": "leaveView" @@ -1076,6 +1076,9 @@ { "name": "renderInitialStylingValues" }, + { + "name": "renderStringify" + }, { "name": "renderStyling" }, @@ -1187,9 +1190,6 @@ { "name": "stringify" }, - { - "name": "stringify$1" - }, { "name": "syncViewWithBlueprint" }, diff --git a/tools/symbol-extractor/symbol_extractor.ts b/tools/symbol-extractor/symbol_extractor.ts index 3a5e90f40b..7fb2b349c9 100644 --- a/tools/symbol-extractor/symbol_extractor.ts +++ b/tools/symbol-extractor/symbol_extractor.ts @@ -47,7 +47,7 @@ export class SymbolExtractor { case ts.SyntaxKind.VariableDeclaration: const varDecl = child as ts.VariableDeclaration; if (varDecl.initializer && fnRecurseDepth !== 0) { - symbols.push({name: varDecl.name.getText()}); + symbols.push({name: stripSuffix(varDecl.name.getText())}); } if (fnRecurseDepth == 0 && isRollupExportSymbol(varDecl)) { ts.forEachChild(child, visitor); @@ -55,7 +55,7 @@ export class SymbolExtractor { break; case ts.SyntaxKind.FunctionDeclaration: const funcDecl = child as ts.FunctionDeclaration; - funcDecl.name && symbols.push({name: funcDecl.name.getText()}); + funcDecl.name && symbols.push({name: stripSuffix(funcDecl.name.getText())}); break; default: // Left for easier debugging. @@ -109,6 +109,11 @@ export class SymbolExtractor { } } +function stripSuffix(text: string): string { + const index = text.lastIndexOf('$'); + return index > -1 ? text.substring(0, index) : text; +} + function toSymbol(v: string | Symbol): Symbol { return typeof v == 'string' ? {'name': v} : v as Symbol; } diff --git a/tools/symbol-extractor/symbol_extractor_spec/drop_trailing_suffix.js b/tools/symbol-extractor/symbol_extractor_spec/drop_trailing_suffix.js new file mode 100644 index 0000000000..49e3f3acda --- /dev/null +++ b/tools/symbol-extractor/symbol_extractor_spec/drop_trailing_suffix.js @@ -0,0 +1,12 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +!function() { + 'use strict'; + var constant$1 = 1, method$2 = function() {}, clazz$3 = class {}; +}(); \ No newline at end of file diff --git a/tools/symbol-extractor/symbol_extractor_spec/drop_trailing_suffix.json b/tools/symbol-extractor/symbol_extractor_spec/drop_trailing_suffix.json new file mode 100644 index 0000000000..1f180d75c6 --- /dev/null +++ b/tools/symbol-extractor/symbol_extractor_spec/drop_trailing_suffix.json @@ -0,0 +1,5 @@ +[ + "clazz", + "constant", + "method" +] \ No newline at end of file diff --git a/tools/symbol-extractor/symbol_extractor_spec/hello_world_min_debug.json b/tools/symbol-extractor/symbol_extractor_spec/hello_world_min_debug.json index aab644f771..c7a0e25210 100644 --- a/tools/symbol-extractor/symbol_extractor_spec/hello_world_min_debug.json +++ b/tools/symbol-extractor/symbol_extractor_spec/hello_world_min_debug.json @@ -1,9 +1,10 @@ -[ "EMPTY$1", +[ + "EMPTY", "NO_CHANGE", - "Symbol$1", - "__global$1", - "__self$1", - "__window$1", + "Symbol", + "__global", + "__self", + "__window", "_renderCompCount", "_root", "createLNode", @@ -13,11 +14,11 @@ "invertObject", "leaveView", "locateHostElement", - "noop$2", + "noop", "refreshDynamicChildren", "renderComponentOrTemplate", "renderEmbeddedTemplate", - "stringify$1", + "stringify", "canInsertNativeNode", "createTView", "executeHooks",