Skip to content

Commit 14ac7ad

Browse files
vicbbenlesh
authored andcommitted
feat(ivy): implement TestBed (angular#25369)
PR Close angular#25369
1 parent 8510637 commit 14ac7ad

37 files changed

+1543
-363
lines changed

build.sh

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ source ${currentDir}/scripts/ci/_travis-fold.sh
88
# TODO(i): wrap into subshell, so that we don't pollute CWD, but not yet to minimize diff collision with Jason
99
cd ${currentDir}
1010

11-
PACKAGES=(core
12-
compiler
11+
PACKAGES=(compiler
12+
core
1313
common
1414
animations
1515
platform-browser
@@ -27,7 +27,8 @@ PACKAGES=(core
2727
service-worker
2828
elements)
2929

30-
TSC_PACKAGES=(compiler-cli
30+
TSC_PACKAGES=(compiler
31+
compiler-cli
3132
language-service
3233
benchpress)
3334

@@ -239,7 +240,13 @@ compilePackage() {
239240
# For TSC_PACKAGES items
240241
if containsElement "${3}" "${TSC_PACKAGES[@]}"; then
241242
echo "====== [${3}]: COMPILING: ${TSC} -p ${1}/tsconfig-build.json"
243+
local package_name=$(basename "${2}")
242244
$TSC -p ${1}/tsconfig-build.json
245+
if [[ "${3}" = "compiler" ]]; then
246+
if [[ "${package_name}" = "testing" ]]; then
247+
echo "$(cat ${LICENSE_BANNER}) ${N} export * from './${package_name}/${package_name}'" > ${2}/../${package_name}.d.ts
248+
fi
249+
fi
243250
else
244251
echo "====== [${3}]: COMPILING: ${NGC} -p ${1}/tsconfig-build.json"
245252
local package_name=$(basename "${2}")

integration/bazel/BUILD.bazel

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ filegroup(
2424

2525
ANGULAR_TESTING = [
2626
"node_modules/@angular/*/bundles/*-testing.umd.js",
27-
# We use AOT, so the compiler and the dynamic platform-browser should be
28-
# visible only in tests
29-
"node_modules/@angular/compiler/bundles/*.umd.js",
27+
# We use AOT, so the dynamic platform-browser should be visible only in tests
28+
# NOTE that we still need to include the compiler because the core depends on it
3029
"node_modules/@angular/platform-browser-dynamic/bundles/*.umd.js",
3130
]
3231

integration/hello_world__closure/closure.conf

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ node_modules/zone.js/dist/zone_externs.js
1919
--js node_modules/rxjs/operators/package.json
2020
--js node_modules/rxjs/_esm2015/operators/index.js
2121

22+
--js node_modules/@angular/compiler/package.json
23+
--js node_modules/@angular/compiler/fesm2015/compiler.js
24+
2225
--js node_modules/@angular/core/package.json
2326
--js node_modules/@angular/core/fesm2015/core.js
2427
--js node_modules/@angular/core/src/testability/testability.externs.js

integration/i18n/closure.conf

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ node_modules/zone.js/dist/zone_externs.js
1717
--module_resolution=node
1818
--package_json_entry_names es2015
1919

20+
--js node_modules/@angular/compiler/package.json
21+
--js node_modules/@angular/compiler/fesm2015/compiler.js
22+
2023
--js node_modules/@angular/core/package.json
2124
--js node_modules/@angular/core/fesm2015/core.js
2225
--js node_modules/@angular/core/src/testability/testability.externs.js

integration/i18n/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli",
1010
"@angular/core": "file:../../dist/packages-dist/core",
1111
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
12+
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic",
1213
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
1314
"google-closure-compiler": "git+https://github.com/alexeagle/closure-compiler.git#packagejson.dist",
1415
"rxjs": "file:../../node_modules/rxjs",
@@ -30,4 +31,4 @@
3031
"preprotractor": "tsc -p e2e",
3132
"protractor": "protractor e2e/protractor.config.js"
3233
}
33-
}
34+
}

integration/i18n/yarn.lock

+48-15
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,48 @@
33

44

55
"@angular/animations@file:../../dist/packages-dist/animations":
6-
version "6.0.0-beta.7-8203e0365a"
6+
version "7.0.0-beta.1-d2d510089c"
77
dependencies:
88
tslib "^1.9.0"
99

1010
"@angular/common@file:../../dist/packages-dist/common":
11-
version "6.0.0-beta.7-8203e0365a"
11+
version "7.0.0-beta.1-d2d510089c"
1212
dependencies:
1313
tslib "^1.9.0"
1414

1515
"@angular/compiler-cli@file:../../dist/packages-dist/compiler-cli":
16-
version "6.0.0-beta.7-8203e0365a"
16+
version "7.0.0-beta.1-d2d510089c"
1717
dependencies:
1818
chokidar "^1.4.2"
19+
convert-source-map "^1.5.1"
20+
magic-string "^0.25.0"
1921
minimist "^1.2.0"
2022
reflect-metadata "^0.1.2"
21-
tsickle "^0.27.2"
23+
source-map "^0.6.1"
24+
tsickle "^0.32.1"
2225

2326
"@angular/compiler@file:../../dist/packages-dist/compiler":
24-
version "6.0.0-beta.7-8203e0365a"
27+
version "7.0.0-beta.1-d2d510089c"
2528
dependencies:
2629
tslib "^1.9.0"
2730

2831
"@angular/core@file:../../dist/packages-dist/core":
29-
version "6.0.0-beta.7-8203e0365a"
32+
version "7.0.0-beta.1-d2d510089c"
33+
dependencies:
34+
tslib "^1.9.0"
35+
36+
"@angular/platform-browser-dynamic@file:../../dist/packages-dist/platform-browser-dynamic":
37+
version "7.0.0-beta.1-d2d510089c"
3038
dependencies:
3139
tslib "^1.9.0"
3240

3341
"@angular/platform-browser@file:../../dist/packages-dist/platform-browser":
34-
version "6.0.0-beta.7-8203e0365a"
42+
version "7.0.0-beta.1-d2d510089c"
3543
dependencies:
3644
tslib "^1.9.0"
3745

3846
"@angular/platform-server@file:../../dist/packages-dist/platform-server":
39-
version "6.0.0-beta.7-8203e0365a"
47+
version "7.0.0-beta.1-d2d510089c"
4048
dependencies:
4149
domino "^2.0.1"
4250
tslib "^1.9.0"
@@ -510,6 +518,10 @@ console-control-strings@^1.0.0, console-control-strings@~1.1.0:
510518
version "1.1.0"
511519
resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e"
512520

521+
convert-source-map@^1.5.1:
522+
version "1.5.1"
523+
resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.5.1.tgz#b8278097b9bc229365de5c62cf5fcaed8b5599e5"
524+
513525
514526
version "0.3.1"
515527
resolved "https://registry.yarnpkg.com/cookie/-/cookie-0.3.1.tgz#e7e0a1f9ef43b4c8ba925c5c5a96e806d16873bb"
@@ -612,6 +624,10 @@ dev-ip@^1.0.1:
612624
version "1.0.1"
613625
resolved "https://registry.yarnpkg.com/dev-ip/-/dev-ip-1.0.1.tgz#a76a3ed1855be7a012bb8ac16cb80f3c00dc28f0"
614626

627+
diff@^3.2.0:
628+
version "3.5.0"
629+
resolved "https://registry.yarnpkg.com/diff/-/diff-3.5.0.tgz#800c0dd1e0a8bfbc95835c202ad220fe317e5a12"
630+
615631
domino@^2.0.1:
616632
version "2.0.1"
617633
resolved "https://registry.yarnpkg.com/domino/-/domino-2.0.1.tgz#9e1d63215d0fe8dcb8202bff07effa1a216db504"
@@ -1203,6 +1219,12 @@ jasmine-core@~2.8.0:
12031219
version "2.8.0"
12041220
resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-2.8.0.tgz#bcc979ae1f9fd05701e45e52e65d3a5d63f1a24e"
12051221

1222+
jasmine-diff@^0.1.3:
1223+
version "0.1.3"
1224+
resolved "https://registry.yarnpkg.com/jasmine-diff/-/jasmine-diff-0.1.3.tgz#93ccc2dcc41028c5ddd4606558074839f2deeaa8"
1225+
dependencies:
1226+
diff "^3.2.0"
1227+
12061228
jasmine@^2.5.3:
12071229
version "2.8.0"
12081230
resolved "https://registry.yarnpkg.com/jasmine/-/jasmine-2.8.0.tgz#6b089c0a11576b1f16df11b80146d91d4e8b8a3e"
@@ -1319,6 +1341,12 @@ lodash@^4.11.1, lodash@^4.5.1:
13191341
version "4.17.4"
13201342
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
13211343

1344+
magic-string@^0.25.0:
1345+
version "0.25.0"
1346+
resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.0.tgz#1f3696f9931ff0a1ed4c132250529e19cad6759b"
1347+
dependencies:
1348+
sourcemap-codec "^1.4.1"
1349+
13221350
[email protected], micromatch@^2.1.5:
13231351
version "2.3.11"
13241352
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565"
@@ -1835,7 +1863,7 @@ [email protected]:
18351863
resolved "https://registry.yarnpkg.com/rx/-/rx-4.1.0.tgz#a5f13ff79ef3b740fe30aa803fb09f98805d4782"
18361864

18371865
"rxjs@file:../../node_modules/rxjs":
1838-
version "6.0.0-alpha.4"
1866+
version "6.0.0"
18391867
dependencies:
18401868
tslib "^1.9.0"
18411869

@@ -2016,10 +2044,14 @@ source-map@^0.5.1, source-map@^0.5.6:
20162044
version "0.5.7"
20172045
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
20182046

2019-
source-map@^0.6.0:
2047+
source-map@^0.6.0, source-map@^0.6.1:
20202048
version "0.6.1"
20212049
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
20222050

2051+
sourcemap-codec@^1.4.1:
2052+
version "1.4.1"
2053+
resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.1.tgz#c8fd92d91889e902a07aee392bdd2c5863958ba2"
2054+
20232055
spawn-command@^0.0.2-1:
20242056
version "0.0.2"
20252057
resolved "https://registry.yarnpkg.com/spawn-command/-/spawn-command-0.0.2.tgz#9544e1a43ca045f8531aac1a48cb29bdae62338e"
@@ -2180,10 +2212,11 @@ tree-kill@^1.1.0:
21802212
version "1.2.0"
21812213
resolved "https://registry.yarnpkg.com/tree-kill/-/tree-kill-1.2.0.tgz#5846786237b4239014f05db156b643212d4c6f36"
21822214

2183-
tsickle@^0.27.2:
2184-
version "0.27.2"
2185-
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.27.2.tgz#f33d46d046f73dd5c155a37922e422816e878736"
2215+
tsickle@^0.32.1:
2216+
version "0.32.1"
2217+
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.32.1.tgz#f16e94ba80b32fc9ebe320dc94fbc2ca7f3521a5"
21862218
dependencies:
2219+
jasmine-diff "^0.1.3"
21872220
minimist "^1.2.0"
21882221
mkdirp "^0.5.1"
21892222
source-map "^0.6.0"
@@ -2204,7 +2237,7 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0:
22042237
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
22052238

22062239
"typescript@file:../../node_modules/typescript":
2207-
version "2.7.2"
2240+
version "2.9.2"
22082241

22092242
22102243
version "0.7.12"
@@ -2424,4 +2457,4 @@ [email protected]:
24242457
resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419"
24252458

24262459
"zone.js@file:../../node_modules/zone.js":
2427-
version "0.8.20"
2460+
version "0.8.26"

packages/compiler/src/lifecycle_reflector.ts

+7
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,12 @@ function getHookName(hook: LifecycleHooks): string {
5252
return 'ngAfterViewInit';
5353
case LifecycleHooks.AfterViewChecked:
5454
return 'ngAfterViewChecked';
55+
default:
56+
// This default case is not needed by TypeScript compiler, as the switch is exhaustive.
57+
// However Closure Compiler does not understand that and reports an error in typed mode.
58+
// The `throw new Error` below works around the problem, and the unexpected: never variable
59+
// makes sure tsc still checks this code is unreachable.
60+
const unexpected: never = hook;
61+
throw new Error(`unexpected ${unexpected}`);
5562
}
5663
}

packages/compiler/src/metadata_resolver.ts

+3-6
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,13 @@ export class CompileMetadataResolver {
115115
return this.getGeneratedClass(dirType, cpl.hostViewClassName(dirType));
116116
}
117117

118-
getHostComponentType(dirType: any): StaticSymbol|Type {
118+
getHostComponentType(dirType: any): StaticSymbol|cpl.ProxyClass {
119119
const name = `${cpl.identifierName({reference: dirType})}_Host`;
120120
if (dirType instanceof StaticSymbol) {
121121
return this._staticSymbolCache.get(dirType.filePath, name);
122-
} else {
123-
const HostClass = <any>function HostClass() {};
124-
HostClass.overriddenName = name;
125-
126-
return HostClass;
127122
}
123+
124+
return this._createProxyClass(dirType, name);
128125
}
129126

130127
private getRendererType(dirType: any): StaticSymbol|object {

packages/compiler/src/view_compiler/view_compiler.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,8 @@ function needsAdditionalRootNode(astNodes: TemplateAst[]): boolean {
940940

941941

942942
function elementBindingDef(inputAst: BoundElementPropertyAst, dirAst: DirectiveAst): o.Expression {
943-
switch (inputAst.type) {
943+
const inputType = inputAst.type;
944+
switch (inputType) {
944945
case PropertyBindingType.Attribute:
945946
return o.literalArr([
946947
o.literal(BindingFlags.TypeElementAttribute), o.literal(inputAst.name),
@@ -965,6 +966,13 @@ function elementBindingDef(inputAst: BoundElementPropertyAst, dirAst: DirectiveA
965966
return o.literalArr([
966967
o.literal(BindingFlags.TypeElementStyle), o.literal(inputAst.name), o.literal(inputAst.unit)
967968
]);
969+
default:
970+
// This default case is not needed by TypeScript compiler, as the switch is exhaustive.
971+
// However Closure Compiler does not understand that and reports an error in typed mode.
972+
// The `throw new Error` below works around the problem, and the unexpected: never variable
973+
// makes sure tsc still checks this code is unreachable.
974+
const unexpected: never = inputType;
975+
throw new Error(`unexpected ${unexpected}`);
968976
}
969977
}
970978

packages/core/src/core_render3_private_export.ts

+30-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export {
1515
detectChanges as ɵdetectChanges,
1616
renderComponent as ɵrenderComponent,
1717
ComponentType as ɵComponentType,
18+
ComponentFactory as ɵRender3ComponentFactory,
19+
ComponentRef as ɵRender3ComponentRef,
1820
DirectiveType as ɵDirectiveType,
1921
RenderFlags as ɵRenderFlags,
2022
directiveInject as ɵdirectiveInject,
@@ -29,6 +31,7 @@ export {
2931
InheritDefinitionFeature as ɵInheritDefinitionFeature,
3032
NgOnChangesFeature as ɵNgOnChangesFeature,
3133
NgModuleType as ɵNgModuleType,
34+
NgModuleRef as ɵRender3NgModuleRef,
3235
CssSelectorList as ɵCssSelectorList,
3336
markDirty as ɵmarkDirty,
3437
NgModuleFactory as ɵNgModuleFactory,
@@ -95,6 +98,7 @@ export {
9598
ld as ɵld,
9699
Pp as ɵPp,
97100
ComponentDef as ɵComponentDef,
101+
ComponentDefInternal as ɵComponentDefInternal,
98102
DirectiveDef as ɵDirectiveDef,
99103
PipeDef as ɵPipeDef,
100104
whenRendered as ɵwhenRendered,
@@ -112,19 +116,43 @@ export {
112116
iM as ɵiM,
113117
I18nInstruction as ɵI18nInstruction,
114118
I18nExpInstruction as ɵI18nExpInstruction,
119+
WRAP_RENDERER_FACTORY2 as ɵWRAP_RENDERER_FACTORY2,
120+
Render3DebugRendererFactory2 as ɵRender3DebugRendererFactory2,
115121
} from './render3/index';
116-
export {NgModuleDef as ɵNgModuleDef} from './metadata/ng_module';
122+
123+
124+
export {
125+
compileNgModuleDefs as ɵcompileNgModuleDefs,
126+
patchComponentDefWithScope as ɵpatchComponentDefWithScope,
127+
} from './render3/jit/module';
128+
129+
export {
130+
compileComponent as ɵcompileComponent,
131+
compileDirective as ɵcompileDirective,
132+
} from './render3/jit/directive';
133+
134+
export {
135+
compilePipe as ɵcompilePipe,
136+
} from './render3/jit/pipe';
137+
138+
export {
139+
NgModuleDef as ɵNgModuleDef,
140+
NgModuleDefInternal as ɵNgModuleDefInternal,
141+
NgModuleTransitiveScopes as ɵNgModuleTransitiveScopes,
142+
} from './metadata/ng_module';
143+
117144
export {
118145
sanitizeHtml as ɵsanitizeHtml,
119146
sanitizeStyle as ɵsanitizeStyle,
120147
sanitizeUrl as ɵsanitizeUrl,
121148
sanitizeResourceUrl as ɵsanitizeResourceUrl,
122149
} from './sanitization/sanitization';
150+
123151
export {
124152
bypassSanitizationTrustHtml as ɵbypassSanitizationTrustHtml,
125153
bypassSanitizationTrustStyle as ɵbypassSanitizationTrustStyle,
126154
bypassSanitizationTrustScript as ɵbypassSanitizationTrustScript,
127155
bypassSanitizationTrustUrl as ɵbypassSanitizationTrustUrl,
128156
bypassSanitizationTrustResourceUrl as ɵbypassSanitizationTrustResourceUrl,
129157
} from './sanitization/bypass';
130-
// clang-format on
158+
// clang-format on

0 commit comments

Comments
 (0)