chore: remove old public api tests
the tests under tools/public_api_guard have better coverage - we no longer need to maintain two copies.
This commit is contained in:
parent
d781e69948
commit
a738d0d54d
|
@ -1,603 +0,0 @@
|
|||
import {
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xdescribe,
|
||||
xit
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
import {IS_DART, RegExpWrapper, StringWrapper} from '../facade/src/lang';
|
||||
import {getSymbolsFromLibrary} from './symbol_inspector/symbol_inspector';
|
||||
import {ListWrapper} from '../facade/src/collection';
|
||||
|
||||
// =================================================================================================
|
||||
// =================================================================================================
|
||||
// =========== S T O P - S T O P - S T O P - S T O P - S T O P - S T O P ===========
|
||||
// =================================================================================================
|
||||
// =================================================================================================
|
||||
//
|
||||
// DO NOT EDIT THIS LIST OF PUBLIC APIS UNLESS YOU GET IT CLEARED BY: mhevery, vsavkin, or tbosch!
|
||||
//
|
||||
// =================================================================================================
|
||||
// =================================================================================================
|
||||
// Note that this test only tests for *values* exported (e.g. classes, functions, variables), but
|
||||
// not for *types* exported (interfaces, typedefs).
|
||||
// See tools/public_api_guard/public_api_spec.ts for a type based test.
|
||||
// =================================================================================================
|
||||
|
||||
|
||||
var COMMON: string[] = [
|
||||
'APP_BASE_HREF',
|
||||
'HashLocationStrategy',
|
||||
'Location',
|
||||
'LocationStrategy',
|
||||
'PathLocationStrategy',
|
||||
'PlatformLocation',
|
||||
'AbstractControl',
|
||||
'AbstractControlDirective',
|
||||
'AsyncPipe',
|
||||
'COMMON_DIRECTIVES',
|
||||
'COMMON_PIPES',
|
||||
'CORE_DIRECTIVES',
|
||||
'CheckboxControlValueAccessor',
|
||||
'Control',
|
||||
'ControlArray',
|
||||
'ControlContainer',
|
||||
'ControlGroup',
|
||||
'ControlValueAccessor:dart',
|
||||
'CurrencyPipe',
|
||||
'DatePipe',
|
||||
'DecimalPipe',
|
||||
'DefaultValueAccessor',
|
||||
'FORM_DIRECTIVES',
|
||||
'FORM_PROVIDERS',
|
||||
'Form:dart',
|
||||
'FormBuilder',
|
||||
'I18nPluralPipe',
|
||||
'I18nSelectPipe',
|
||||
'JsonPipe',
|
||||
'LowerCasePipe',
|
||||
'MaxLengthValidator',
|
||||
'MinLengthValidator',
|
||||
'NG_ASYNC_VALIDATORS',
|
||||
'NG_VALIDATORS',
|
||||
'NG_VALUE_ACCESSOR',
|
||||
'NgClass',
|
||||
'NgControl',
|
||||
'NgControlGroup',
|
||||
'NgControlName',
|
||||
'NgControlStatus',
|
||||
'NgFor',
|
||||
'NgForm',
|
||||
'NgFormControl',
|
||||
'NgFormModel',
|
||||
'NgIf',
|
||||
'NgTemplateOutlet',
|
||||
'NgModel',
|
||||
'NgSelectOption',
|
||||
'NgStyle',
|
||||
'NgSwitch',
|
||||
'NgSwitchWhen',
|
||||
'NgSwitchDefault',
|
||||
'ObservableListDiff:dart',
|
||||
'ObservableListDiffFactory:dart',
|
||||
'PatternValidator',
|
||||
'PercentPipe',
|
||||
'ReplacePipe',
|
||||
'RequiredValidator',
|
||||
'SelectControlValueAccessor',
|
||||
'SlicePipe',
|
||||
'UpperCasePipe',
|
||||
'Validator:dart',
|
||||
'Validators',
|
||||
'RadioButtonState',
|
||||
'NgLocalization',
|
||||
'NgPlural',
|
||||
'NgPluralCase'
|
||||
];
|
||||
|
||||
var COMMON_TESTING: string[] = ['MockLocationStrategy', 'SpyLocation'];
|
||||
|
||||
var COMPILER: string[] = [
|
||||
'ElementSchemaRegistry',
|
||||
'__compiler_private__',
|
||||
"TemplateAst:dart",
|
||||
"TemplateAstVisitor:dart",
|
||||
"DEFAULT_PACKAGE_URL_PROVIDER",
|
||||
"UrlResolver",
|
||||
"AttrAst",
|
||||
"BoundDirectivePropertyAst",
|
||||
"BoundElementPropertyAst",
|
||||
"BoundEventAst",
|
||||
"BoundTextAst",
|
||||
"COMPILER_PROVIDERS",
|
||||
"CompileDirectiveMetadata",
|
||||
"CompileTemplateMetadata",
|
||||
"CompileTypeMetadata",
|
||||
"DirectiveAst",
|
||||
"ElementAst",
|
||||
"EmbeddedTemplateAst",
|
||||
"NgContentAst",
|
||||
"PropertyBindingType",
|
||||
"SourceModule",
|
||||
"TEMPLATE_TRANSFORMS",
|
||||
"TextAst",
|
||||
"VariableAst",
|
||||
"ReferenceAst",
|
||||
"XHR",
|
||||
"templateVisitAll",
|
||||
"CompileDiDependencyMetadata",
|
||||
"CompileFactoryMetadata",
|
||||
"CompileIdentifierMetadata",
|
||||
"CompileMetadataWithIdentifier",
|
||||
"CompileMetadataWithType",
|
||||
"CompilePipeMetadata",
|
||||
"CompileProviderMetadata",
|
||||
"CompileQueryMetadata",
|
||||
"CompileTokenMetadata",
|
||||
"CompilerConfig",
|
||||
"RenderTypes",
|
||||
"DirectiveResolver",
|
||||
"NormalizedComponentWithViewDirectives",
|
||||
"OfflineCompiler",
|
||||
"RuntimeCompiler",
|
||||
"PipeResolver",
|
||||
"ProviderAst",
|
||||
"ProviderAstType",
|
||||
"ViewResolver",
|
||||
"createOfflineCompileUrlResolver"
|
||||
];
|
||||
|
||||
var COMPILER_TESTING: string[] = [
|
||||
'ComponentFixture',
|
||||
'ComponentFixtureAutoDetect',
|
||||
'ComponentFixtureNoNgZone',
|
||||
'MockDirectiveResolver',
|
||||
'MockSchemaRegistry',
|
||||
'MockViewResolver',
|
||||
'MockXHR',
|
||||
'TestComponentBuilder',
|
||||
'TestComponentRenderer'
|
||||
];
|
||||
|
||||
// API Classification audited
|
||||
var CORE: string[] = [
|
||||
'__core_private__',
|
||||
'BaseException',
|
||||
'DefaultIterableDiffer',
|
||||
'getDebugNode',
|
||||
'wtfCreateScope',
|
||||
'wtfEndTimeRange',
|
||||
'wtfLeave',
|
||||
'wtfStartTimeRange',
|
||||
'APP_INITIALIZER',
|
||||
'APP_ID',
|
||||
'AbstractProviderError',
|
||||
'AUTO_STYLE',
|
||||
'AnimationAnimateMetadata',
|
||||
'AnimationEntryMetadata',
|
||||
'AnimationGroupMetadata',
|
||||
'AnimationMetadata',
|
||||
'AnimationSequenceMetadata',
|
||||
'AnimationStateDeclarationMetadata',
|
||||
'AnimationStateMetadata',
|
||||
'AnimationStateTransitionMetadata',
|
||||
'AnimationStyleMetadata',
|
||||
'AnimationWithStepsMetadata',
|
||||
'AnimationKeyframesSequenceMetadata',
|
||||
'AnimationPlayer',
|
||||
'animate',
|
||||
'group',
|
||||
'sequence',
|
||||
'state',
|
||||
'style',
|
||||
'keyframes',
|
||||
'trigger',
|
||||
'transition',
|
||||
'ApplicationRef',
|
||||
'APPLICATION_COMMON_PROVIDERS',
|
||||
'Attribute',
|
||||
'AttributeMetadata',
|
||||
'Binding',
|
||||
'Provider',
|
||||
'ProviderBuilder',
|
||||
'PLATFORM_DIRECTIVES',
|
||||
"CollectionChangeRecord",
|
||||
'ChangeDetectionStrategy',
|
||||
'ChangeDetectorRef',
|
||||
'Class',
|
||||
'ComponentResolver',
|
||||
'SystemJsComponentResolver',
|
||||
'Component',
|
||||
'ComponentMetadata',
|
||||
'ComponentRef',
|
||||
'ContentChild',
|
||||
'ContentChildMetadata',
|
||||
'ContentChildren',
|
||||
'ContentChildrenMetadata',
|
||||
'CyclicDependencyError',
|
||||
'PLATFORM_PIPES',
|
||||
'DebugNode',
|
||||
'DebugElement',
|
||||
'Directive',
|
||||
'DirectiveMetadata',
|
||||
'DynamicComponentLoader',
|
||||
'ElementRef',
|
||||
'Output',
|
||||
'EmbeddedViewRef',
|
||||
'EventEmitter',
|
||||
'ExceptionHandler',
|
||||
'OutputMetadata',
|
||||
'enableProdMode',
|
||||
'ExpressionChangedAfterItHasBeenCheckedException',
|
||||
'Host',
|
||||
'HostBinding',
|
||||
'HostBindingMetadata',
|
||||
'HostListener',
|
||||
'HostListenerMetadata',
|
||||
'HostMetadata',
|
||||
'ComponentFactory',
|
||||
'Inject',
|
||||
'InjectMetadata',
|
||||
'Injectable',
|
||||
'InjectableMetadata',
|
||||
'Injector',
|
||||
'ReflectiveInjector',
|
||||
'InstantiationError',
|
||||
'InvalidProviderError',
|
||||
'IterableDiffers',
|
||||
'ReflectiveKey',
|
||||
'KeyValueChangeRecord',
|
||||
'KeyValueDiffers',
|
||||
'NgZone',
|
||||
'NgZoneError',
|
||||
'NoAnnotationError',
|
||||
'NoProviderError',
|
||||
'OpaqueToken',
|
||||
'Optional',
|
||||
'OptionalMetadata',
|
||||
'OutOfBoundsError',
|
||||
'Pipe',
|
||||
'PipeMetadata',
|
||||
'PlatformRef',
|
||||
'Input',
|
||||
'InputMetadata',
|
||||
'Query',
|
||||
'QueryList',
|
||||
'QueryMetadata',
|
||||
'Renderer',
|
||||
'RootRenderer',
|
||||
'RenderComponentType',
|
||||
'ResolvedReflectiveFactory',
|
||||
'Self',
|
||||
'SelfMetadata',
|
||||
'SkipSelf',
|
||||
'SkipSelfMetadata',
|
||||
'SimpleChange',
|
||||
'TemplateRef',
|
||||
'Testability',
|
||||
'TestabilityRegistry',
|
||||
'setTestabilityGetter',
|
||||
'Type',
|
||||
'PACKAGE_ROOT_URL',
|
||||
'ViewChild',
|
||||
'ViewChildMetadata',
|
||||
'ViewChildren',
|
||||
'ViewChildrenMetadata',
|
||||
'ViewContainerRef',
|
||||
'ViewEncapsulation',
|
||||
'ViewMetadata',
|
||||
'ViewQuery',
|
||||
'ViewQueryMetadata',
|
||||
'WrappedException',
|
||||
'WrappedValue',
|
||||
'asNativeElements',
|
||||
'bind',
|
||||
'provide',
|
||||
'createNgZone',
|
||||
'forwardRef',
|
||||
'coreBootstrap',
|
||||
'coreLoadAndBootstrap',
|
||||
'createPlatform',
|
||||
'disposePlatform',
|
||||
'getPlatform',
|
||||
'assertPlatform',
|
||||
'resolveForwardRef',
|
||||
'PLATFORM_COMMON_PROVIDERS',
|
||||
'PLATFORM_INITIALIZER',
|
||||
'AfterContentChecked',
|
||||
'AfterContentInit',
|
||||
'AfterViewChecked',
|
||||
'AfterViewInit',
|
||||
'DoCheck',
|
||||
'OnChanges',
|
||||
'OnDestroy',
|
||||
'OnInit',
|
||||
'ViewRef',
|
||||
];
|
||||
|
||||
var CORE_TESTING: string[] = [
|
||||
'InjectSetupWrapper',
|
||||
'Log',
|
||||
'MockApplicationRef',
|
||||
'MockNgZone',
|
||||
'TestInjector',
|
||||
'afterEach',
|
||||
'async',
|
||||
'beforeEach',
|
||||
'beforeEachProviders',
|
||||
'clearPendingTimers',
|
||||
'containsRegexp',
|
||||
'ddescribe',
|
||||
'describe',
|
||||
'expect',
|
||||
'fakeAsync',
|
||||
'fdescribe',
|
||||
'fit',
|
||||
'flushMicrotasks',
|
||||
'getTestInjector',
|
||||
'getTypeOf',
|
||||
'iit',
|
||||
'inject',
|
||||
'injectAsync',
|
||||
'instantiateType',
|
||||
'it',
|
||||
'resetBaseTestProviders',
|
||||
'setBaseTestProviders',
|
||||
'tick',
|
||||
'discardPeriodicTasks',
|
||||
'withProviders',
|
||||
'xdescribe',
|
||||
'xit'
|
||||
];
|
||||
|
||||
var PLATFORM_BROWSER: string[] = [
|
||||
'__platform_browser_private__',
|
||||
'AngularEntrypoint:dart',
|
||||
'bootstrap',
|
||||
'bootstrapApp',
|
||||
'bootstrapRender',
|
||||
'BROWSER_APP_PROVIDERS',
|
||||
'BROWSER_APP_COMPILER_PROVIDERS',
|
||||
'BROWSER_PLATFORM_PROVIDERS',
|
||||
'BROWSER_PROVIDERS',
|
||||
'BROWSER_SANITIZATION_PROVIDERS',
|
||||
'browserPlatform',
|
||||
'BrowserPlatformLocation',
|
||||
'By',
|
||||
'CACHED_TEMPLATE_PROVIDER',
|
||||
'ClientMessageBroker',
|
||||
'ClientMessageBrokerFactory',
|
||||
'disableDebugTools',
|
||||
'DOCUMENT',
|
||||
'DomEventsPlugin',
|
||||
'DomSanitizationService',
|
||||
'ELEMENT_PROBE_PROVIDERS',
|
||||
'enableDebugTools',
|
||||
'EVENT_MANAGER_PLUGINS',
|
||||
'EventManager',
|
||||
'FnArg',
|
||||
'HAMMER_GESTURE_CONFIG',
|
||||
'HammerGestureConfig',
|
||||
'initializeGenericWorkerRenderer',
|
||||
'KeyEventsPlugin',
|
||||
'MessageBus',
|
||||
'PRIMITIVE',
|
||||
'ReceivedMessage',
|
||||
'SecurityContext',
|
||||
'ServiceMessageBroker',
|
||||
'ServiceMessageBrokerFactory',
|
||||
'Title',
|
||||
'UiArguments',
|
||||
'UrlChangeEvent:dart',
|
||||
'UrlChangeListener:dart',
|
||||
'WebWorkerInstance',
|
||||
'WORKER_APP_APPLICATION_PROVIDERS',
|
||||
'WORKER_APP_LOCATION_PROVIDERS',
|
||||
'WORKER_APP_PLATFORM_PROVIDERS',
|
||||
'WORKER_RENDER_APPLICATION_PROVIDERS',
|
||||
'WORKER_RENDER_LOCATION_PROVIDERS',
|
||||
'WORKER_RENDER_PLATFORM_PROVIDERS',
|
||||
'WORKER_RENDER_STARTABLE_MESSAGING_SERVICE',
|
||||
'WORKER_SCRIPT',
|
||||
'workerAppPlatform',
|
||||
'workerRenderPlatform'
|
||||
];
|
||||
|
||||
var PLATFORM_BROWSER_TESTING: string[] = [
|
||||
'ADDITIONAL_TEST_BROWSER_PROVIDERS', // This should be made private
|
||||
'ADDITIONAL_TEST_BROWSER_STATIC_PROVIDERS', // This should be made private
|
||||
'BrowserDetection',
|
||||
'browserDetection',
|
||||
'dispatchEvent',
|
||||
'DOMTestComponentRenderer',
|
||||
'el',
|
||||
'expect',
|
||||
'normalizeCSS',
|
||||
'stringifyElement',
|
||||
'TEST_BROWSER_APPLICATION_PROVIDERS',
|
||||
'TEST_BROWSER_PLATFORM_PROVIDERS',
|
||||
'TEST_BROWSER_STATIC_APPLICATION_PROVIDERS',
|
||||
'TEST_BROWSER_STATIC_PLATFORM_PROVIDERS'
|
||||
];
|
||||
|
||||
var PLATFORM_SERVER: string[] = ['Parse5DomAdapter'];
|
||||
|
||||
var PLATFORM_SERVER_TESTING: string[] =
|
||||
['TEST_SERVER_APPLICATION_PROVIDERS', 'TEST_SERVER_PLATFORM_PROVIDERS'];
|
||||
|
||||
var UPGRADE: string[] = [
|
||||
'UpgradeAdapter',
|
||||
'UpgradeAdapterRef',
|
||||
];
|
||||
|
||||
var HTTP: string[] = [
|
||||
'BaseRequestOptions',
|
||||
'BaseResponseOptions',
|
||||
'BrowserXhr',
|
||||
'Connection',
|
||||
'ConnectionBackend',
|
||||
'CookieXSRFStrategy',
|
||||
'HTTP_BINDINGS',
|
||||
'HTTP_PROVIDERS',
|
||||
'Headers',
|
||||
'Http',
|
||||
'JSONPBackend',
|
||||
'JSONPConnection',
|
||||
'JSONP_PROVIDERS',
|
||||
'JSON_BINDINGS',
|
||||
'Jsonp',
|
||||
'ReadyState',
|
||||
'Request',
|
||||
'RequestMethod',
|
||||
'RequestOptions',
|
||||
'Response',
|
||||
'ResponseOptions',
|
||||
'ResponseType',
|
||||
'URLSearchParams',
|
||||
'XHRBackend',
|
||||
'XHRConnection',
|
||||
'XSRFStrategy',
|
||||
];
|
||||
|
||||
var HTTP_TESTING: string[] = ['MockBackend', 'MockConnection'];
|
||||
|
||||
var ROUTER_DEPRECATED: string[] = [
|
||||
'AsyncRoute',
|
||||
'AuxRoute',
|
||||
'CanActivate',
|
||||
'ComponentInstruction',
|
||||
'Instruction',
|
||||
'OpaqueToken',
|
||||
'ROUTER_BINDINGS',
|
||||
'ROUTER_DIRECTIVES',
|
||||
'ROUTER_PRIMARY_COMPONENT',
|
||||
'ROUTER_PROVIDERS',
|
||||
'ROUTER_PROVIDERS_COMMON',
|
||||
'Redirect',
|
||||
'Route',
|
||||
'RouteConfig',
|
||||
'RouteData',
|
||||
'RouteParams',
|
||||
'RouteRegistry',
|
||||
'Router',
|
||||
'RouterLink',
|
||||
'RouterOutlet'
|
||||
];
|
||||
|
||||
var ROUTER_DEPRECATED_TESTING: string[] = [];
|
||||
|
||||
|
||||
var ROUTER: string[] = [
|
||||
'ROUTER_DIRECTIVES',
|
||||
'ROUTER_PROVIDERS',
|
||||
'Route',
|
||||
'Router',
|
||||
'RouterOutlet',
|
||||
'RouterLink',
|
||||
'DefaultRouterUrlSerializer',
|
||||
'RouteSegment',
|
||||
'RouteTree',
|
||||
'RouterOutletMap',
|
||||
'RouterUrlSerializer',
|
||||
'Routes',
|
||||
'Tree',
|
||||
'UrlSegment',
|
||||
'UrlTree'
|
||||
];
|
||||
|
||||
var ROUTER_TESTING: string[] = ['ROUTER_FAKE_PROVIDERS'];
|
||||
|
||||
|
||||
var API = {
|
||||
'common': COMMON,
|
||||
'common/testing': COMMON_TESTING,
|
||||
'compiler': COMPILER,
|
||||
'compiler/testing': COMPILER_TESTING,
|
||||
'core': CORE,
|
||||
'core/testing': CORE_TESTING,
|
||||
'http': HTTP,
|
||||
'http/testing': HTTP_TESTING,
|
||||
'router-deprecated': ROUTER_DEPRECATED,
|
||||
'router-deprecated/testing': ROUTER_DEPRECATED_TESTING,
|
||||
'router': ROUTER,
|
||||
'router/testing': ROUTER_TESTING,
|
||||
'upgrade': UPGRADE,
|
||||
'platform-browser': PLATFORM_BROWSER,
|
||||
'platform-browser/testing': PLATFORM_BROWSER_TESTING,
|
||||
'platform-server': PLATFORM_SERVER,
|
||||
'platform-server/testing': PLATFORM_SERVER_TESTING
|
||||
};
|
||||
|
||||
export function main() {
|
||||
/**
|
||||
var x = getSymbolsFromLibrary('ng');
|
||||
x.sort();
|
||||
var parts = [];
|
||||
x.forEach((i) => parts.push(`'${i'`));
|
||||
print(`[ ${parts.join(',
|
||||
')} ]`);
|
||||
*/
|
||||
|
||||
describe('public API', () => {
|
||||
var barrelList = [
|
||||
'common',
|
||||
'common/testing',
|
||||
'compiler',
|
||||
'compiler/testing',
|
||||
'core',
|
||||
'core/testing',
|
||||
'http',
|
||||
'http/testing',
|
||||
'router',
|
||||
'router/testing',
|
||||
'upgrade',
|
||||
'platform-browser',
|
||||
'platform-browser/testing',
|
||||
'platform-server',
|
||||
'platform-server/testing'
|
||||
];
|
||||
|
||||
if (IS_DART) {
|
||||
barrelList = barrelList.filter(b => b !== 'upgrade');
|
||||
}
|
||||
|
||||
barrelList.forEach(mod => {
|
||||
// Dom Events are merged into DomAdapter in Dart
|
||||
if (IS_DART && mod === 'ngPlatformDomEvent') return;
|
||||
it(`should fail if public API for ${mod} has changed`, () => {
|
||||
var symbols = getSymbolsFromLibrary(mod);
|
||||
expect(diff(symbols, API[mod])).toEqual([]);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function diff(actual: string[], expected: string[]): string[] {
|
||||
ListWrapper.sort(actual, compareIgnoreLang);
|
||||
ListWrapper.sort(expected, compareIgnoreLang);
|
||||
let mode = IS_DART ? "dart" : "js";
|
||||
let missing = actual.filter(i => expected.indexOf(i) < 0 && expected.indexOf(`${i}:${mode}`) < 0)
|
||||
.map(s => `+${s}`);
|
||||
let extra = expected.filter(i => shouldIgnore(i) ? false : (actual.indexOf(stripLang(i)) < 0))
|
||||
.map(s => `-${s}`);
|
||||
return ListWrapper.concat(missing, extra);
|
||||
}
|
||||
|
||||
function shouldIgnore(expected: string): boolean {
|
||||
let isDart = RegExpWrapper.create('\\:dart$');
|
||||
let isJs = RegExpWrapper.create('\\:js$');
|
||||
return IS_DART ? RegExpWrapper.test(isJs, expected) : RegExpWrapper.test(isDart, expected);
|
||||
}
|
||||
|
||||
function compareIgnoreLang(a: string, b: string): number {
|
||||
return StringWrapper.compare(stripLang(a), stripLang(b));
|
||||
}
|
||||
|
||||
function stripLang(text: string): string {
|
||||
let index = text.indexOf(':');
|
||||
return (index >= 0) ? text.substring(0, index) : text;
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
// A library for the symbol inspector test
|
||||
|
||||
export class A {
|
||||
constructor(b: ConsParamType) {}
|
||||
|
||||
field: FieldType;
|
||||
get getter(): GetterType { return null; }
|
||||
|
||||
method(p: ParamType): MethodReturnType { return null; }
|
||||
|
||||
methodWithFunc(closure: ClosureReturn) {}
|
||||
|
||||
static staticField: StaticFieldType = null;
|
||||
static staticMethod() {}
|
||||
}
|
||||
|
||||
export class ConsParamType {}
|
||||
export class FieldType {}
|
||||
export class GetterType {}
|
||||
export class MethodReturnType {}
|
||||
export class ParamType {}
|
||||
export class StaticFieldType {}
|
||||
|
||||
export class ClosureReturn {}
|
||||
export class ClosureParam {}
|
||||
|
||||
export class TypedefReturnType {}
|
||||
export class TypedefParam {}
|
||||
|
||||
|
||||
export class Generic<K> { // Generic should be exported, but not K.
|
||||
get getter(): K { return null; }
|
||||
}
|
||||
|
||||
export interface SomeInterface { someMethod(); }
|
|
@ -1,194 +0,0 @@
|
|||
library angular.symbol_inspector.symbol_inspector;
|
||||
|
||||
import 'dart:mirrors';
|
||||
import './simple_library.dart' as simple_library;
|
||||
import 'package:angular2/common.dart';
|
||||
import 'package:angular2/compiler.dart';
|
||||
import 'package:angular2/core.dart';
|
||||
import 'package:angular2/instrumentation.dart';
|
||||
import 'package:angular2/platform/browser.dart';
|
||||
|
||||
const IGNORE = const {
|
||||
'runtimeType': true,
|
||||
'toString': true,
|
||||
'noSuchMethod': true,
|
||||
'hashCode': true,
|
||||
'originalException': true,
|
||||
'originalStack': true
|
||||
};
|
||||
|
||||
const LIB_MAP = const {
|
||||
'simple_library': 'angular2.test.symbol_inspector.simple_library',
|
||||
'ngCommon': 'angular2.common',
|
||||
'ngCompiler': 'angular2.compiler',
|
||||
'ngCore': 'angular2.core',
|
||||
'ngInstrumentation': 'angular2.instrumentation',
|
||||
'ngPlatformBrowser': 'angular2.platform.browser',
|
||||
'ngPlatformCommon': 'angular2.platform.common'
|
||||
};
|
||||
|
||||
// Have this list here to trick dart to force import.
|
||||
var libs = [simple_library.A, Component, Form, COMPILER_PROVIDERS, NgIf, wtfCreateScope, Title];
|
||||
|
||||
List<String> getSymbolsFromLibrary(String name) {
|
||||
var libraryName = LIB_MAP[name];
|
||||
if (libs.isEmpty) throw "No libriries loaded.";
|
||||
if (libraryName == null) throw "Don't know how to load '$name' library.";
|
||||
var lib = currentMirrorSystem().findLibrary(new Symbol(libraryName));
|
||||
var names = [];
|
||||
extractSymbols(lib).addTo(names);
|
||||
names.sort();
|
||||
// remove duplicates;
|
||||
var lastValue;
|
||||
names = names.where((v) {
|
||||
var duplicate = v == lastValue;
|
||||
lastValue = v;
|
||||
return !duplicate;
|
||||
}).toList();
|
||||
return names;
|
||||
}
|
||||
|
||||
class ExportedSymbol {
|
||||
Symbol symbol;
|
||||
DeclarationMirror declaration;
|
||||
LibraryMirror library;
|
||||
|
||||
ExportedSymbol(this.symbol, this.declaration, this.library);
|
||||
|
||||
addTo(List<String> names) {
|
||||
var name = unwrapSymbol(symbol);
|
||||
if (declaration is MethodMirror) {
|
||||
names.add(name);
|
||||
} else if (declaration is ClassMirror) {
|
||||
var classMirror = declaration as ClassMirror;
|
||||
if (classMirror.isAbstract) name = '$name';
|
||||
names.add(name);
|
||||
} else if (declaration is TypedefMirror) {
|
||||
names.add(name);
|
||||
} else if (declaration is VariableMirror) {
|
||||
names.add(name);
|
||||
} else {
|
||||
throw 'UNEXPECTED: $declaration';
|
||||
}
|
||||
}
|
||||
|
||||
toString() => unwrapSymbol(symbol);
|
||||
}
|
||||
|
||||
class LibraryInfo {
|
||||
List<ExportedSymbol> names;
|
||||
Map<Symbol, List<Symbol>> symbolsUsedForName;
|
||||
|
||||
LibraryInfo(this.names, this.symbolsUsedForName);
|
||||
|
||||
addTo(List<String> names) {
|
||||
this.names.forEach((ExportedSymbol es) => es.addTo(names));
|
||||
//this.names.addAll(symbolsUsedForName.keys.map(unwrapSymbol));
|
||||
}
|
||||
}
|
||||
|
||||
Iterable<Symbol> _getUsedSymbols(
|
||||
DeclarationMirror decl, seenDecls, path, onlyType) {
|
||||
if (seenDecls.containsKey(decl.qualifiedName)) return [];
|
||||
seenDecls[decl.qualifiedName] = true;
|
||||
|
||||
if (decl.isPrivate) return [];
|
||||
|
||||
path = "$path -> $decl";
|
||||
|
||||
var used = [];
|
||||
|
||||
if (decl is TypedefMirror) {
|
||||
TypedefMirror tddecl = decl;
|
||||
used.addAll(_getUsedSymbols(tddecl.referent, seenDecls, path, onlyType));
|
||||
}
|
||||
if (decl is FunctionTypeMirror) {
|
||||
FunctionTypeMirror ftdecl = decl;
|
||||
|
||||
ftdecl.parameters.forEach((ParameterMirror p) {
|
||||
used.addAll(_getUsedSymbols(p.type, seenDecls, path, onlyType));
|
||||
});
|
||||
used.addAll(_getUsedSymbols(ftdecl.returnType, seenDecls, path, onlyType));
|
||||
} else if (decl is TypeMirror) {
|
||||
var tdecl = decl;
|
||||
used.add(tdecl.qualifiedName);
|
||||
}
|
||||
|
||||
if (!onlyType) {
|
||||
if (decl is ClassMirror) {
|
||||
ClassMirror cdecl = decl;
|
||||
cdecl.declarations.forEach((s, d) {
|
||||
try {
|
||||
used.addAll(_getUsedSymbols(d, seenDecls, path, false));
|
||||
} catch (e, s) {
|
||||
print("Got error [$e] when visiting $d\n$s");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Strip out type variables.
|
||||
if (decl is TypeMirror) {
|
||||
TypeMirror tdecl = decl;
|
||||
var typeVariables = tdecl.typeVariables.map((tv) => tv.qualifiedName);
|
||||
used = used.where((x) => !typeVariables.contains(x));
|
||||
}
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
LibraryInfo extractSymbols(LibraryMirror lib, [String printPrefix = ""]) {
|
||||
List<ExportedSymbol> exportedSymbols = [];
|
||||
Map<Symbol, List<Symbol>> used = {};
|
||||
|
||||
printPrefix += " ";
|
||||
lib.declarations.forEach((Symbol symbol, DeclarationMirror decl) {
|
||||
if (decl.isPrivate) return;
|
||||
|
||||
// Work-around for dartbug.com/18271
|
||||
if (decl is TypedefMirror && unwrapSymbol(symbol).startsWith('_')) return;
|
||||
|
||||
exportedSymbols.add(new ExportedSymbol(symbol, decl, lib));
|
||||
used[decl.qualifiedName] = _getUsedSymbols(decl, {}, "", false);
|
||||
});
|
||||
|
||||
lib.libraryDependencies.forEach((LibraryDependencyMirror libDep) {
|
||||
LibraryMirror target = libDep.targetLibrary;
|
||||
if (!libDep.isExport) return;
|
||||
|
||||
var childInfo = extractSymbols(target, printPrefix);
|
||||
var childNames = childInfo.names;
|
||||
|
||||
// If there was a "show" or "hide" on the exported library, filter the results.
|
||||
// This API needs love :-(
|
||||
var showSymbols = [], hideSymbols = [];
|
||||
libDep.combinators.forEach((CombinatorMirror c) {
|
||||
if (c.isShow) {
|
||||
showSymbols.addAll(c.identifiers);
|
||||
}
|
||||
if (c.isHide) {
|
||||
hideSymbols.addAll(c.identifiers);
|
||||
}
|
||||
});
|
||||
|
||||
// I don't think you can show and hide from the same library
|
||||
assert(showSymbols.isEmpty || hideSymbols.isEmpty);
|
||||
if (!showSymbols.isEmpty) {
|
||||
childNames = childNames.where((symAndLib) {
|
||||
return showSymbols.contains(symAndLib.symbol);
|
||||
});
|
||||
}
|
||||
if (!hideSymbols.isEmpty) {
|
||||
childNames = childNames.where((symAndLib) {
|
||||
return !hideSymbols.contains(symAndLib.symbol);
|
||||
});
|
||||
}
|
||||
|
||||
exportedSymbols.addAll(childNames);
|
||||
used.addAll(childInfo.symbolsUsedForName);
|
||||
});
|
||||
return new LibraryInfo(exportedSymbols, used);
|
||||
}
|
||||
|
||||
var _SYMBOL_NAME = new RegExp('"(.*)"');
|
||||
unwrapSymbol(sym) => _SYMBOL_NAME.firstMatch(sym.toString()).group(1);
|
|
@ -1,66 +0,0 @@
|
|||
import * as simple_library from './simple_library';
|
||||
import * as core from '@angular/core';
|
||||
import * as core_testing from '@angular/core/testing';
|
||||
import * as common from '@angular/common';
|
||||
import * as common_testing from '@angular/common/testing';
|
||||
import * as compiler from '@angular/compiler';
|
||||
import * as compiler_testing from '@angular/compiler/testing';
|
||||
import * as http from '@angular/http';
|
||||
import * as http_testing from '@angular/http/testing';
|
||||
import * as router_deprecated from '@angular/router-deprecated';
|
||||
import * as router_deprecated_testing from '@angular/router-deprecated/testing';
|
||||
import * as router from '@angular/router';
|
||||
import * as router_testing from '@angular/router/testing';
|
||||
import * as upgrade from '@angular/upgrade';
|
||||
import * as platformBrowser from '@angular/platform-browser';
|
||||
import * as platformBrowser_testing from '@angular/platform-browser/testing';
|
||||
import * as platformServer from '@angular/platform-server';
|
||||
import * as platformServer_testing from '@angular/platform-server/testing';
|
||||
|
||||
const LIB_MAP = {
|
||||
'simple_library': simple_library,
|
||||
'common': common,
|
||||
'common/testing': common_testing,
|
||||
'compiler': compiler,
|
||||
'compiler/testing': compiler_testing,
|
||||
'core': core,
|
||||
'core/testing': core_testing,
|
||||
'http': http,
|
||||
'http/testing': http_testing,
|
||||
'router-deprecated': router_deprecated,
|
||||
'router-deprecated/testing': router_deprecated_testing,
|
||||
'router': router,
|
||||
'router/testing': router_testing,
|
||||
'upgrade': upgrade,
|
||||
'platform-browser': platformBrowser,
|
||||
'platform-browser/testing': platformBrowser_testing,
|
||||
'platform-server': platformServer,
|
||||
'platform-server/testing': platformServer_testing
|
||||
};
|
||||
|
||||
const IGNORE =
|
||||
{
|
||||
captureStackTrace: true,
|
||||
stackTraceLimit: true,
|
||||
toString: true,
|
||||
originalException: true,
|
||||
originalStack: true,
|
||||
wrapperMessage: true,
|
||||
wrapperStack: true, '@@observable': true
|
||||
};
|
||||
|
||||
function collectTopLevelSymbols(prefix: string, lib: any):
|
||||
string[] {
|
||||
var symbols: string[] = [];
|
||||
for (var name in lib) {
|
||||
var symbol = `${name}`;
|
||||
symbols.push(symbol);
|
||||
}
|
||||
return symbols;
|
||||
}
|
||||
|
||||
export function getSymbolsFromLibrary(name: string): string[] {
|
||||
var symbols = collectTopLevelSymbols(name, LIB_MAP[name]);
|
||||
symbols.sort();
|
||||
return symbols;
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
import {
|
||||
beforeEach,
|
||||
ddescribe,
|
||||
describe,
|
||||
expect,
|
||||
iit,
|
||||
inject,
|
||||
it,
|
||||
xdescribe,
|
||||
xit
|
||||
} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {IS_DART} from '../../facade/src/lang';
|
||||
import {getSymbolsFromLibrary} from './symbol_inspector';
|
||||
|
||||
export function main() {
|
||||
describe('symbol inspector', () => {
|
||||
if (IS_DART) {
|
||||
it('should extract symbols (dart)', () => {
|
||||
var symbols = getSymbolsFromLibrary("simple_library");
|
||||
expect(symbols).toEqual([
|
||||
'A',
|
||||
'ClosureParam',
|
||||
'ClosureReturn',
|
||||
'ConsParamType',
|
||||
'FieldType',
|
||||
'Generic',
|
||||
'GetterType',
|
||||
'MethodReturnType',
|
||||
'ParamType',
|
||||
'SomeInterface',
|
||||
'StaticFieldType',
|
||||
'TypedefParam',
|
||||
'TypedefReturnType'
|
||||
]);
|
||||
});
|
||||
} else {
|
||||
it('should extract symbols (js)', () => {
|
||||
var symbols = getSymbolsFromLibrary("simple_library");
|
||||
expect(symbols).toEqual([
|
||||
'A',
|
||||
'ClosureParam',
|
||||
'ClosureReturn',
|
||||
'ConsParamType',
|
||||
'FieldType',
|
||||
'Generic',
|
||||
'GetterType',
|
||||
'MethodReturnType',
|
||||
'ParamType',
|
||||
'StaticFieldType',
|
||||
'TypedefParam',
|
||||
'TypedefReturnType'
|
||||
]);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue