/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/compiler-cli/linker/src/linker_import_generator.ts
47 строк
1 KB
Kristiyan Kostadinov
fix(compiler): ensure generated code compiles
13 мар 2026, 20:13
13 мар 2026, 20:13
412788f
Код
Авторство
О чём код?
/** * @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.dev/license */ import {AstFactory, ImportGenerator, ImportRequest} from '../../src/ngtsc/translator'; import {FatalLinkerError} from './fatal_linker_error'; /** * A class that is used to generate imports when translating from Angular Output AST to an AST to * render, such as Babel. * * Note that, in the linker, there can only be imports from `@angular/core` and that these imports * must be achieved by property access on an `ng` namespace identifier, which is passed in via the * constructor. */ export class LinkerImportGenerator<TStatement, TExpression, TType> implements ImportGenerator< null, TExpression > { constructor( private factory: AstFactory<TStatement, TExpression, TType>, private ngImport: TExpression, ) {} addImport(request: ImportRequest<null>): TExpression { this.assertModuleName(request.exportModuleSpecifier); if (request.exportSymbolName === null) { return this.ngImport; } return this.factory.createPropertyAccess(this.ngImport, request.exportSymbolName); } private assertModuleName(moduleName: string): void { if (moduleName !== '@angular/core') { throw new FatalLinkerError( this.ngImport, `Unable to import from anything other than '@angular/core'`, ); } } }