2018-09-11 21:11:32 -04:00
|
|
|
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
|
2018-07-16 03:49:56 -04:00
|
|
|
|
2019-01-16 04:19:01 -05:00
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
|
2018-07-16 03:49:56 -04:00
|
|
|
ts_library(
|
|
|
|
name = "test_lib",
|
2018-10-16 02:24:22 -04:00
|
|
|
testonly = True,
|
2019-03-20 09:47:58 -04:00
|
|
|
srcs = glob(
|
|
|
|
["**/*.ts"],
|
|
|
|
exclude = ["integration/**/*.ts"],
|
|
|
|
),
|
2018-07-16 03:49:56 -04:00
|
|
|
deps = [
|
2019-03-20 09:47:58 -04:00
|
|
|
"//packages/compiler-cli/ngcc",
|
2018-12-18 12:48:15 -05:00
|
|
|
"//packages/compiler-cli/src/ngtsc/imports",
|
|
|
|
"//packages/compiler-cli/src/ngtsc/partial_evaluator",
|
feat(ivy): use fileNameToModuleName to emit imports when it's available (#28523)
The ultimate goal of this commit is to make use of fileNameToModuleName to
get the module specifier to use when generating an import, when that API is
available in the CompilerHost that ngtsc is created with.
As part of getting there, the way in which ngtsc tracks references and
generates import module specifiers is refactored considerably. References
are tracked with the Reference class, and previously ngtsc had several
different kinds of Reference. An AbsoluteReference represented a declaration
which needed to be imported via an absolute module specifier tracked in the
AbsoluteReference, and a RelativeReference represented a declaration from
the local program, imported via relative path or referred to directly by
identifier if possible. Thus, how to refer to a particular declaration was
encoded into the Reference type _at the time of creation of the Reference_.
This commit refactors that logic and reduces Reference to a single class
with no subclasses. A Reference represents a node being referenced, plus
context about how the node was located. This context includes a
"bestGuessOwningModule", the compiler's best guess at which absolute
module specifier has defined this reference. For example, if the compiler
arrives at the declaration of CommonModule via an import to @angular/common,
then any references obtained from CommonModule (e.g. NgIf) will also be
considered to be owned by @angular/common.
A ReferenceEmitter class and accompanying ReferenceEmitStrategy interface
are introduced. To produce an Expression referring to a given Reference'd
node, the ReferenceEmitter consults a sequence of ReferenceEmitStrategy
implementations.
Several different strategies are defined:
- LocalIdentifierStrategy: use local ts.Identifiers if available.
- AbsoluteModuleStrategy: if the Reference has a bestGuessOwningModule,
import the node via an absolute import from that module specifier.
- LogicalProjectStrategy: if the Reference is in the logical project
(is under the project rootDirs), import the node via a relative import.
- FileToModuleStrategy: use a FileToModuleHost to generate the module
specifier by which to import the node.
Depending on the availability of fileNameToModuleName in the CompilerHost,
then, a different collection of these strategies is used for compilation.
PR Close #28523
2019-02-01 20:24:21 -05:00
|
|
|
"//packages/compiler-cli/src/ngtsc/path",
|
2018-12-18 12:48:15 -05:00
|
|
|
"//packages/compiler-cli/src/ngtsc/reflection",
|
2018-07-16 03:49:56 -04:00
|
|
|
"//packages/compiler-cli/src/ngtsc/testing",
|
2018-07-16 03:55:04 -04:00
|
|
|
"//packages/compiler-cli/src/ngtsc/transform",
|
2019-03-20 09:47:58 -04:00
|
|
|
"//packages/compiler-cli/test:test_utils",
|
2019-02-20 12:54:42 -05:00
|
|
|
"@npm//@types/convert-source-map",
|
|
|
|
"@npm//@types/mock-fs",
|
|
|
|
"@npm//canonical-path",
|
|
|
|
"@npm//magic-string",
|
|
|
|
"@npm//typescript",
|
2018-07-16 03:49:56 -04:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
jasmine_node_test(
|
|
|
|
name = "test",
|
|
|
|
bootstrap = ["angular/tools/testing/init_node_no_angular_spec.js"],
|
|
|
|
deps = [
|
|
|
|
":test_lib",
|
|
|
|
"//tools/testing:node_no_angular",
|
2019-02-20 12:54:42 -05:00
|
|
|
"@npm//canonical-path",
|
|
|
|
"@npm//convert-source-map",
|
2018-07-16 03:49:56 -04:00
|
|
|
],
|
|
|
|
)
|
2019-03-20 09:47:58 -04:00
|
|
|
|
|
|
|
ts_library(
|
|
|
|
name = "integration_lib",
|
|
|
|
testonly = True,
|
|
|
|
srcs = glob(
|
|
|
|
["integration/**/*.ts"],
|
|
|
|
),
|
|
|
|
deps = [
|
|
|
|
"//packages/compiler-cli/ngcc",
|
2019-03-20 09:47:58 -04:00
|
|
|
"//packages/compiler-cli/src/ngtsc/path",
|
2019-03-20 09:47:58 -04:00
|
|
|
"//packages/compiler-cli/test:test_utils",
|
|
|
|
"@npm//@types/mock-fs",
|
2019-03-20 09:47:58 -04:00
|
|
|
"@npm//rxjs",
|
2019-03-20 09:47:58 -04:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
|
|
|
jasmine_node_test(
|
|
|
|
name = "integration",
|
|
|
|
bootstrap = ["angular/tools/testing/init_node_no_angular_spec.js"],
|
|
|
|
data = [
|
|
|
|
"//packages/common:npm_package",
|
|
|
|
"//packages/core:npm_package",
|
|
|
|
"@npm//rxjs",
|
|
|
|
],
|
2019-03-20 09:47:58 -04:00
|
|
|
tags = [
|
|
|
|
# Disabled in AOT mode because we want ngcc to compile non-AOT Angular packages.
|
|
|
|
"no-ivy-aot",
|
|
|
|
],
|
2019-03-20 09:47:58 -04:00
|
|
|
deps = [
|
|
|
|
":integration_lib",
|
|
|
|
"//tools/testing:node_no_angular",
|
|
|
|
"@npm//canonical-path",
|
|
|
|
"@npm//convert-source-map",
|
|
|
|
"@npm//shelljs",
|
|
|
|
],
|
|
|
|
)
|