diff --git a/packages/compiler-cli/test/compliance/BUILD.bazel b/packages/compiler-cli/test/compliance/BUILD.bazel index b37fe372c1..e9ca4aae4e 100644 --- a/packages/compiler-cli/test/compliance/BUILD.bazel +++ b/packages/compiler-cli/test/compliance/BUILD.bazel @@ -6,11 +6,15 @@ ts_library( srcs = glob( ["**/*.ts"], ), + visibility = [ + ":__subpackages__", + ], deps = [ "//packages:types", "//packages/compiler", "//packages/compiler-cli", "//packages/compiler-cli/src/ngtsc/file_system", + "//packages/compiler-cli/test/compliance/mock_compile", "//packages/compiler/test:test_utils", "@npm//typescript", ], diff --git a/packages/compiler-cli/test/compliance/mock_compile/BUILD.bazel b/packages/compiler-cli/test/compliance/mock_compile/BUILD.bazel new file mode 100644 index 0000000000..0dd814d256 --- /dev/null +++ b/packages/compiler-cli/test/compliance/mock_compile/BUILD.bazel @@ -0,0 +1,19 @@ +load("//tools:defaults.bzl", "ts_library") + +ts_library( + name = "mock_compile", + testonly = True, + srcs = ["index.ts"], + visibility = [ + "//packages/compiler-cli/test/compliance:__subpackages__", + ], + deps = [ + "//packages:types", + "//packages/compiler", + "//packages/compiler-cli", + "//packages/compiler-cli/src/ngtsc/core:api", + "//packages/compiler-cli/src/ngtsc/file_system", + "//packages/compiler/test:test_utils", + "@npm//typescript", + ], +) diff --git a/packages/compiler-cli/test/compliance/mock_compile.ts b/packages/compiler-cli/test/compliance/mock_compile/index.ts similarity index 91% rename from packages/compiler-cli/test/compliance/mock_compile.ts rename to packages/compiler-cli/test/compliance/mock_compile/index.ts index 2f4185c8bd..4c56d03741 100644 --- a/packages/compiler-cli/test/compliance/mock_compile.ts +++ b/packages/compiler-cli/test/compliance/mock_compile/index.ts @@ -5,13 +5,13 @@ * 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 */ -import {AotCompilerOptions} from '@angular/compiler'; import {escapeRegExp} from '@angular/compiler/src/util'; import {arrayToMockDir, MockCompilerHost, MockData, MockDirectory, toMockFileArray} from '@angular/compiler/test/aot/test_util'; import * as ts from 'typescript'; -import {NodeJSFileSystem, setFileSystem} from '../../src/ngtsc/file_system'; -import {NgtscProgram} from '../../src/ngtsc/program'; +import {NgCompilerOptions} from '../../../src/ngtsc/core/api'; +import {NodeJSFileSystem, setFileSystem} from '../../../src/ngtsc/file_system'; +import {NgtscProgram} from '../../../src/ngtsc/program'; const IDENTIFIER = /[A-Za-z_$ɵ][A-Za-z0-9_$]*/; const OPERATOR = @@ -196,12 +196,8 @@ function buildMatcher(pieces: (string|RegExp)[]): {regexp: RegExp, groups: Map void = error => { - throw error; - }): { +export function doCompile( + data: MockDirectory, angularFiles: MockData, options: NgCompilerOptions = {}): { source: string, } { setFileSystem(new NodeJSFileSystem()); @@ -226,3 +222,18 @@ export function compile( return {source}; } + +export type CompileFn = typeof doCompile; + +/** + * The actual compile function that will be used to compile the test code. + * This can be updated by a test bootstrap script to provide an alternative compile function. + */ +export let compile: CompileFn = doCompile; + +/** + * Update the `compile` exported function to use a new implementation. + */ +export function setCompileFn(compileFn: CompileFn) { + compile = compileFn; +} diff --git a/packages/compiler-cli/test/compliance/prelink/BUILD.bazel b/packages/compiler-cli/test/compliance/prelink/BUILD.bazel new file mode 100644 index 0000000000..c0e657d274 --- /dev/null +++ b/packages/compiler-cli/test/compliance/prelink/BUILD.bazel @@ -0,0 +1,29 @@ +load("//tools:defaults.bzl", "jasmine_node_test", "ts_library") + +ts_library( + name = "prelink_bootstrap", + testonly = True, + srcs = ["bootstrap.ts"], + deps = [ + "//packages:types", + "//packages/compiler-cli/test/compliance/mock_compile", + ], +) + +jasmine_node_test( + name = "prelink", + bootstrap = [ + "//tools/testing:node_no_angular_es5", + ":prelink_bootstrap_es5", + ], + data = [ + "//packages/compiler-cli/test/ngtsc/fake_core:npm_package", + ], + shard_count = 4, + tags = [ + "ivy-only", + ], + deps = [ + "//packages/compiler-cli/test/compliance:test_lib", + ], +) diff --git a/packages/compiler-cli/test/compliance/prelink/bootstrap.ts b/packages/compiler-cli/test/compliance/prelink/bootstrap.ts new file mode 100644 index 0000000000..38d8efa990 --- /dev/null +++ b/packages/compiler-cli/test/compliance/prelink/bootstrap.ts @@ -0,0 +1,27 @@ +/** + * @license + * Copyright Google LLC 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 + */ +import {CompileFn, doCompile, setCompileFn} from '../mock_compile'; + +/** + * A function to compile the given code in two steps: + * + * - first compile the code in partial mode + * - then compile the partially compiled code using the linker + * + * This should produce the same output as the full AOT compilation + */ +const linkedCompile: CompileFn = (data, angularFiles, options) => { + const result = doCompile(data, angularFiles, {...options, compilationMode: 'partial'}); + // TODO: additional post linking + return result; +}; + +// Update the function that will do the compiling with this specialised version that +// runs the prelink and postlink parts of AOT compilation, to check it produces the +// same result as a normal full AOT compile. +setCompileFn(linkedCompile);