refactor(localize): update to use new file-system interfaces (#40281)

Now that `ReadonlyFileSystem` and `PathManipulation` interfaces are
available, this commit updates the localize package to use these more
focussed interfaces.

PR Close #40281
This commit is contained in:
Pete Bacon Darwin 2020-12-30 17:04:04 +00:00 committed by Andrew Scott
parent d100a15998
commit bb6d791dab
19 changed files with 43 additions and 51 deletions

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {AbsoluteFsPath, FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {AbsoluteFsPath, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {ɵMessageId, ɵParsedMessage} from '@angular/localize'; import {ɵMessageId, ɵParsedMessage} from '@angular/localize';
import {DiagnosticHandlingStrategy, Diagnostics} from '../diagnostics'; import {DiagnosticHandlingStrategy, Diagnostics} from '../diagnostics';
@ -17,7 +17,7 @@ import {serializeLocationPosition} from '../source_file_utils';
* object (as necessary). * object (as necessary).
*/ */
export function checkDuplicateMessages( export function checkDuplicateMessages(
fs: FileSystem, messages: ɵParsedMessage[], fs: PathManipulation, messages: ɵParsedMessage[],
duplicateMessageHandling: DiagnosticHandlingStrategy, basePath: AbsoluteFsPath): Diagnostics { duplicateMessageHandling: DiagnosticHandlingStrategy, basePath: AbsoluteFsPath): Diagnostics {
const diagnostics = new Diagnostics(); const diagnostics = new Diagnostics();
if (duplicateMessageHandling === 'ignore') return diagnostics; if (duplicateMessageHandling === 'ignore') return diagnostics;
@ -47,7 +47,7 @@ export function checkDuplicateMessages(
* Serialize the given `message` object into a string. * Serialize the given `message` object into a string.
*/ */
function serializeMessage( function serializeMessage(
fs: FileSystem, basePath: AbsoluteFsPath, message: ɵParsedMessage): string { fs: PathManipulation, basePath: AbsoluteFsPath, message: ɵParsedMessage): string {
if (message.location === undefined) { if (message.location === undefined) {
return ` - "${message.text}"`; return ` - "${message.text}"`;
} else { } else {

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {AbsoluteFsPath, FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {AbsoluteFsPath, ReadonlyFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system';
import {Logger} from '@angular/compiler-cli/src/ngtsc/logging'; import {Logger} from '@angular/compiler-cli/src/ngtsc/logging';
import {SourceFile, SourceFileLoader} from '@angular/compiler-cli/src/ngtsc/sourcemaps'; import {SourceFile, SourceFileLoader} from '@angular/compiler-cli/src/ngtsc/sourcemaps';
import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize';
@ -33,7 +33,7 @@ export class MessageExtractor {
private loader: SourceFileLoader; private loader: SourceFileLoader;
constructor( constructor(
private fs: FileSystem, private logger: Logger, private fs: ReadonlyFileSystem, private logger: Logger,
{basePath, useSourceMaps = true, localizeName = '$localize'}: ExtractionOptions) { {basePath, useSourceMaps = true, localizeName = '$localize'}: ExtractionOptions) {
this.basePath = basePath; this.basePath = basePath;
this.useSourceMaps = useSourceMaps; this.useSourceMaps = useSourceMaps;

View File

@ -6,7 +6,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {setFileSystem, NodeJSFileSystem, AbsoluteFsPath, FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {setFileSystem, NodeJSFileSystem, AbsoluteFsPath, FileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {ConsoleLogger, Logger, LogLevel} from '@angular/compiler-cli/src/ngtsc/logging'; import {ConsoleLogger, Logger, LogLevel} from '@angular/compiler-cli/src/ngtsc/logging';
import {ɵParsedMessage} from '@angular/localize'; import {ɵParsedMessage} from '@angular/localize';
import * as glob from 'glob'; import * as glob from 'glob';
@ -214,7 +214,7 @@ export function extractTranslations({
export function getSerializer( export function getSerializer(
format: string, sourceLocale: string, rootPath: AbsoluteFsPath, useLegacyIds: boolean, format: string, sourceLocale: string, rootPath: AbsoluteFsPath, useLegacyIds: boolean,
formatOptions: FormatOptions = {}, fs: FileSystem): TranslationSerializer { formatOptions: FormatOptions = {}, fs: PathManipulation): TranslationSerializer {
switch (format) { switch (format) {
case 'xlf': case 'xlf':
case 'xlif': case 'xlif':

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {ɵParsedMessage, ɵparseMessage} from '@angular/localize'; import {ɵParsedMessage, ɵparseMessage} from '@angular/localize';
import {NodePath, PluginObj} from '@babel/core'; import {NodePath, PluginObj} from '@babel/core';
import {TaggedTemplateExpression} from '@babel/types'; import {TaggedTemplateExpression} from '@babel/types';
@ -13,7 +13,7 @@ import {TaggedTemplateExpression} from '@babel/types';
import {getLocation, isGlobalIdentifier, isNamedIdentifier, unwrapExpressionsFromTemplateLiteral, unwrapMessagePartsFromTemplateLiteral} from '../../source_file_utils'; import {getLocation, isGlobalIdentifier, isNamedIdentifier, unwrapExpressionsFromTemplateLiteral, unwrapMessagePartsFromTemplateLiteral} from '../../source_file_utils';
export function makeEs2015ExtractPlugin( export function makeEs2015ExtractPlugin(
fs: FileSystem, messages: ɵParsedMessage[], localizeName = '$localize'): PluginObj { fs: PathManipulation, messages: ɵParsedMessage[], localizeName = '$localize'): PluginObj {
return { return {
visitor: { visitor: {
TaggedTemplateExpression(path: NodePath<TaggedTemplateExpression>) { TaggedTemplateExpression(path: NodePath<TaggedTemplateExpression>) {

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {ɵParsedMessage, ɵparseMessage} from '@angular/localize'; import {ɵParsedMessage, ɵparseMessage} from '@angular/localize';
import {NodePath, PluginObj} from '@babel/core'; import {NodePath, PluginObj} from '@babel/core';
import {CallExpression} from '@babel/types'; import {CallExpression} from '@babel/types';
@ -13,7 +13,7 @@ import {CallExpression} from '@babel/types';
import {getLocation, isGlobalIdentifier, isNamedIdentifier, unwrapMessagePartsFromLocalizeCall, unwrapSubstitutionsFromLocalizeCall} from '../../source_file_utils'; import {getLocation, isGlobalIdentifier, isNamedIdentifier, unwrapMessagePartsFromLocalizeCall, unwrapSubstitutionsFromLocalizeCall} from '../../source_file_utils';
export function makeEs5ExtractPlugin( export function makeEs5ExtractPlugin(
fs: FileSystem, messages: ɵParsedMessage[], localizeName = '$localize'): PluginObj { fs: PathManipulation, messages: ɵParsedMessage[], localizeName = '$localize'): PluginObj {
return { return {
visitor: { visitor: {
CallExpression(callPath: NodePath<CallExpression>) { CallExpression(callPath: NodePath<CallExpression>) {

View File

@ -5,9 +5,8 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {AbsoluteFsPath, FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {AbsoluteFsPath, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize';
import {ArbJsonObject, ArbLocation, ArbMetadata} from '../../translate/translation_files/translation_parsers/arb_translation_parser';
import {TranslationSerializer} from './translation_serializer'; import {TranslationSerializer} from './translation_serializer';
import {consolidateMessages, hasLocation} from './utils'; import {consolidateMessages, hasLocation} from './utils';
@ -45,7 +44,8 @@ import {consolidateMessages, hasLocation} from './utils';
*/ */
export class ArbTranslationSerializer implements TranslationSerializer { export class ArbTranslationSerializer implements TranslationSerializer {
constructor( constructor(
private sourceLocale: string, private basePath: AbsoluteFsPath, private fs: FileSystem) {} private sourceLocale: string, private basePath: AbsoluteFsPath,
private fs: PathManipulation) {}
serialize(messages: ɵParsedMessage[]): string { serialize(messages: ɵParsedMessage[]): string {
const messageGroups = consolidateMessages(messages, message => getMessageId(message)); const messageGroups = consolidateMessages(messages, message => getMessageId(message));

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {AbsoluteFsPath, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {AbsoluteFsPath, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize';
import {FormatOptions, validateOptions} from './format_options'; import {FormatOptions, validateOptions} from './format_options';
@ -29,7 +29,7 @@ const LEGACY_XLIFF_MESSAGE_LENGTH = 40;
export class Xliff1TranslationSerializer implements TranslationSerializer { export class Xliff1TranslationSerializer implements TranslationSerializer {
constructor( constructor(
private sourceLocale: string, private basePath: AbsoluteFsPath, private useLegacyIds: boolean, private sourceLocale: string, private basePath: AbsoluteFsPath, private useLegacyIds: boolean,
private formatOptions: FormatOptions = {}, private fs: FileSystem = getFileSystem()) { private formatOptions: FormatOptions = {}, private fs: PathManipulation = getFileSystem()) {
validateOptions('Xliff1TranslationSerializer', [['xml:space', ['preserve']]], formatOptions); validateOptions('Xliff1TranslationSerializer', [['xml:space', ['preserve']]], formatOptions);
} }

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {AbsoluteFsPath, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {AbsoluteFsPath, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize';
import {FormatOptions, validateOptions} from './format_options'; import {FormatOptions, validateOptions} from './format_options';
@ -29,7 +29,7 @@ export class Xliff2TranslationSerializer implements TranslationSerializer {
private currentPlaceholderId = 0; private currentPlaceholderId = 0;
constructor( constructor(
private sourceLocale: string, private basePath: AbsoluteFsPath, private useLegacyIds: boolean, private sourceLocale: string, private basePath: AbsoluteFsPath, private useLegacyIds: boolean,
private formatOptions: FormatOptions = {}, private fs: FileSystem = getFileSystem()) { private formatOptions: FormatOptions = {}, private fs: PathManipulation = getFileSystem()) {
validateOptions('Xliff1TranslationSerializer', [['xml:space', ['preserve']]], formatOptions); validateOptions('Xliff1TranslationSerializer', [['xml:space', ['preserve']]], formatOptions);
} }

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {AbsoluteFsPath, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {AbsoluteFsPath, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize';
import {extractIcuPlaceholders} from './icu_parsing'; import {extractIcuPlaceholders} from './icu_parsing';
@ -24,7 +24,7 @@ import {XmlFile} from './xml_file';
export class XmbTranslationSerializer implements TranslationSerializer { export class XmbTranslationSerializer implements TranslationSerializer {
constructor( constructor(
private basePath: AbsoluteFsPath, private useLegacyIds: boolean, private basePath: AbsoluteFsPath, private useLegacyIds: boolean,
private fs: FileSystem = getFileSystem()) {} private fs: PathManipulation = getFileSystem()) {}
serialize(messages: ɵParsedMessage[]): string { serialize(messages: ɵParsedMessage[]): string {
const messageGroups = consolidateMessages(messages, message => this.getMessageId(message)); const messageGroups = consolidateMessages(messages, message => this.getMessageId(message));

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {AbsoluteFsPath, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {AbsoluteFsPath, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {ɵisMissingTranslationError, ɵmakeTemplateObject, ɵParsedTranslation, ɵSourceLocation, ɵtranslate} from '@angular/localize'; import {ɵisMissingTranslationError, ɵmakeTemplateObject, ɵParsedTranslation, ɵSourceLocation, ɵtranslate} from '@angular/localize';
import {NodePath} from '@babel/traverse'; import {NodePath} from '@babel/traverse';
import * as t from '@babel/types'; import * as t from '@babel/types';
@ -74,7 +74,7 @@ export function buildLocalizeReplacement(
*/ */
export function unwrapMessagePartsFromLocalizeCall( export function unwrapMessagePartsFromLocalizeCall(
call: NodePath<t.CallExpression>, call: NodePath<t.CallExpression>,
fs: FileSystem = getFileSystem(), fs: PathManipulation = getFileSystem(),
): [TemplateStringsArray, (ɵSourceLocation | undefined)[]] { ): [TemplateStringsArray, (ɵSourceLocation | undefined)[]] {
let cooked = call.get('arguments')[0]; let cooked = call.get('arguments')[0];
@ -160,7 +160,7 @@ export function unwrapMessagePartsFromLocalizeCall(
*/ */
export function unwrapSubstitutionsFromLocalizeCall( export function unwrapSubstitutionsFromLocalizeCall(
call: NodePath<t.CallExpression>, call: NodePath<t.CallExpression>,
fs: FileSystem = getFileSystem()): [t.Expression[], (ɵSourceLocation | undefined)[]] { fs: PathManipulation = getFileSystem()): [t.Expression[], (ɵSourceLocation | undefined)[]] {
const expressions = call.get('arguments').splice(1); const expressions = call.get('arguments').splice(1);
if (!isArrayOfExpressions(expressions)) { if (!isArrayOfExpressions(expressions)) {
const badExpression = expressions.find(expression => !expression.isExpression())!; const badExpression = expressions.find(expression => !expression.isExpression())!;
@ -182,8 +182,8 @@ export function unwrapSubstitutionsFromLocalizeCall(
* @publicApi used by CLI * @publicApi used by CLI
*/ */
export function unwrapMessagePartsFromTemplateLiteral( export function unwrapMessagePartsFromTemplateLiteral(
elements: NodePath<t.TemplateElement>[], elements: NodePath<t.TemplateElement>[], fs: PathManipulation = getFileSystem()):
fs: FileSystem = getFileSystem()): [TemplateStringsArray, (ɵSourceLocation | undefined)[]] { [TemplateStringsArray, (ɵSourceLocation | undefined)[]] {
const cooked = elements.map(q => { const cooked = elements.map(q => {
if (q.node.value.cooked === undefined) { if (q.node.value.cooked === undefined) {
throw new BabelParseError( throw new BabelParseError(
@ -207,7 +207,7 @@ export function unwrapMessagePartsFromTemplateLiteral(
*/ */
export function unwrapExpressionsFromTemplateLiteral( export function unwrapExpressionsFromTemplateLiteral(
quasi: NodePath<t.TemplateLiteral>, quasi: NodePath<t.TemplateLiteral>,
fs: FileSystem = getFileSystem()): [t.Expression[], (ɵSourceLocation | undefined)[]] { fs: PathManipulation = getFileSystem()): [t.Expression[], (ɵSourceLocation | undefined)[]] {
return [quasi.node.expressions, quasi.get('expressions').map(e => getLocation(fs, e))]; return [quasi.node.expressions, quasi.get('expressions').map(e => getLocation(fs, e))];
} }
@ -235,7 +235,7 @@ export function wrapInParensIfNecessary(expression: t.Expression): t.Expression
*/ */
export function unwrapStringLiteralArray( export function unwrapStringLiteralArray(
array: NodePath<t.Expression>, array: NodePath<t.Expression>,
fs: FileSystem = getFileSystem()): [string[], (ɵSourceLocation | undefined)[]] { fs: PathManipulation = getFileSystem()): [string[], (ɵSourceLocation | undefined)[]] {
if (!isStringLiteralArray(array.node)) { if (!isStringLiteralArray(array.node)) {
throw new BabelParseError( throw new BabelParseError(
array.node, 'Unexpected messageParts for `$localize` (expected an array of strings).'); array.node, 'Unexpected messageParts for `$localize` (expected an array of strings).');
@ -400,7 +400,7 @@ export function buildCodeFrameError(path: NodePath, e: BabelParseError): string
} }
export function getLocation( export function getLocation(
fs: FileSystem, startPath: NodePath, endPath?: NodePath): ɵSourceLocation|undefined { fs: PathManipulation, startPath: NodePath, endPath?: NodePath): ɵSourceLocation|undefined {
const startLocation = startPath.node.loc; const startLocation = startPath.node.loc;
const file = getFileFromPath(fs, startPath); const file = getFileFromPath(fs, startPath);
if (!startLocation || !file) { if (!startLocation || !file) {
@ -425,7 +425,7 @@ export function serializeLocationPosition(location: ɵSourceLocation): string {
return `${location.start.line + 1}${endLineString}`; return `${location.start.line + 1}${endLineString}`;
} }
function getFileFromPath(fs: FileSystem, path: NodePath|undefined): AbsoluteFsPath|null { function getFileFromPath(fs: PathManipulation, path: NodePath|undefined): AbsoluteFsPath|null {
const opts = path?.hub.file.opts; const opts = path?.hub.file.opts;
return opts?.filename ? return opts?.filename ?
fs.resolve(opts.generatorOpts.sourceRoot ?? opts.cwd, fs.relative(opts.cwd, opts.filename)) : fs.resolve(opts.generatorOpts.sourceRoot ?? opts.cwd, fs.relative(opts.cwd, opts.filename)) :

View File

@ -5,13 +5,12 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {ɵParsedTranslation} from '@angular/localize'; import {ɵParsedTranslation} from '@angular/localize';
import {NodePath, PluginObj} from '@babel/core'; import {NodePath, PluginObj} from '@babel/core';
import {TaggedTemplateExpression} from '@babel/types'; import {TaggedTemplateExpression} from '@babel/types';
import {Diagnostics} from '../../diagnostics'; import {Diagnostics} from '../../diagnostics';
import {buildCodeFrameError, buildLocalizeReplacement, isBabelParseError, isLocalize, translate, TranslatePluginOptions, unwrapMessagePartsFromTemplateLiteral} from '../../source_file_utils'; import {buildCodeFrameError, buildLocalizeReplacement, isBabelParseError, isLocalize, translate, TranslatePluginOptions, unwrapMessagePartsFromTemplateLiteral} from '../../source_file_utils';
/** /**
@ -23,7 +22,7 @@ import {buildCodeFrameError, buildLocalizeReplacement, isBabelParseError, isLoca
export function makeEs2015TranslatePlugin( export function makeEs2015TranslatePlugin(
diagnostics: Diagnostics, translations: Record<string, ɵParsedTranslation>, diagnostics: Diagnostics, translations: Record<string, ɵParsedTranslation>,
{missingTranslation = 'error', localizeName = '$localize'}: TranslatePluginOptions = {}, {missingTranslation = 'error', localizeName = '$localize'}: TranslatePluginOptions = {},
fs: FileSystem = getFileSystem()): PluginObj { fs: PathManipulation = getFileSystem()): PluginObj {
return { return {
visitor: { visitor: {
TaggedTemplateExpression(path: NodePath<TaggedTemplateExpression>) { TaggedTemplateExpression(path: NodePath<TaggedTemplateExpression>) {

View File

@ -5,13 +5,12 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {ɵParsedTranslation} from '@angular/localize'; import {ɵParsedTranslation} from '@angular/localize';
import {NodePath, PluginObj} from '@babel/core'; import {NodePath, PluginObj} from '@babel/core';
import {CallExpression} from '@babel/types'; import {CallExpression} from '@babel/types';
import {Diagnostics} from '../../diagnostics'; import {Diagnostics} from '../../diagnostics';
import {buildCodeFrameError, buildLocalizeReplacement, isBabelParseError, isLocalize, translate, TranslatePluginOptions, unwrapMessagePartsFromLocalizeCall, unwrapSubstitutionsFromLocalizeCall} from '../../source_file_utils'; import {buildCodeFrameError, buildLocalizeReplacement, isBabelParseError, isLocalize, translate, TranslatePluginOptions, unwrapMessagePartsFromLocalizeCall, unwrapSubstitutionsFromLocalizeCall} from '../../source_file_utils';
/** /**
@ -23,7 +22,7 @@ import {buildCodeFrameError, buildLocalizeReplacement, isBabelParseError, isLoca
export function makeEs5TranslatePlugin( export function makeEs5TranslatePlugin(
diagnostics: Diagnostics, translations: Record<string, ɵParsedTranslation>, diagnostics: Diagnostics, translations: Record<string, ɵParsedTranslation>,
{missingTranslation = 'error', localizeName = '$localize'}: TranslatePluginOptions = {}, {missingTranslation = 'error', localizeName = '$localize'}: TranslatePluginOptions = {},
fs: FileSystem = getFileSystem()): PluginObj { fs: PathManipulation = getFileSystem()): PluginObj {
return { return {
visitor: { visitor: {
CallExpression(callPath: NodePath<CallExpression>) { CallExpression(callPath: NodePath<CallExpression>) {

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {AbsoluteFsPath, FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {AbsoluteFsPath, ReadonlyFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system';
import {DiagnosticHandlingStrategy, Diagnostics} from '../../diagnostics'; import {DiagnosticHandlingStrategy, Diagnostics} from '../../diagnostics';
import {TranslationBundle} from '../translator'; import {TranslationBundle} from '../translator';
@ -16,7 +16,7 @@ import {ParseAnalysis, TranslationParser} from './translation_parsers/translatio
*/ */
export class TranslationLoader { export class TranslationLoader {
constructor( constructor(
private fs: FileSystem, private translationParsers: TranslationParser<any>[], private fs: ReadonlyFileSystem, private translationParsers: TranslationParser<any>[],
private duplicateTranslation: DiagnosticHandlingStrategy, private duplicateTranslation: DiagnosticHandlingStrategy,
/** @deprecated */ private diagnostics?: Diagnostics) {} /** @deprecated */ private diagnostics?: Diagnostics) {}

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {AbsoluteFsPath, FileSystem, PathSegment} from '@angular/compiler-cli/src/ngtsc/file_system'; import {AbsoluteFsPath, PathSegment, ReadonlyFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system';
import {ɵMessageId, ɵParsedTranslation} from '@angular/localize'; import {ɵMessageId, ɵParsedTranslation} from '@angular/localize';
import {Diagnostics} from '../diagnostics'; import {Diagnostics} from '../diagnostics';
@ -64,7 +64,7 @@ export interface TranslationHandler {
*/ */
export class Translator { export class Translator {
constructor( constructor(
private fs: FileSystem, private resourceHandlers: TranslationHandler[], private fs: ReadonlyFileSystem, private resourceHandlers: TranslationHandler[],
private diagnostics: Diagnostics) {} private diagnostics: Diagnostics) {}
translateFiles( translateFiles(

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {absoluteFrom, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {absoluteFrom, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing'; import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing';
import {ɵParsedMessage} from '@angular/localize'; import {ɵParsedMessage} from '@angular/localize';
@ -14,7 +14,7 @@ import {ArbTranslationSerializer} from '../../../src/extract/translation_files/a
import {location, mockMessage} from './mock_message'; import {location, mockMessage} from './mock_message';
runInEachFileSystem(() => { runInEachFileSystem(() => {
let fs: FileSystem; let fs: PathManipulation;
describe('ArbTranslationSerializer', () => { describe('ArbTranslationSerializer', () => {
beforeEach(() => { beforeEach(() => {
fs = getFileSystem(); fs = getFileSystem();

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {absoluteFrom, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {absoluteFrom, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing'; import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing';
import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize'; import {ɵParsedMessage, ɵSourceLocation} from '@angular/localize';
@ -14,7 +14,7 @@ import {XmbTranslationSerializer} from '../../../src/extract/translation_files/x
import {location, mockMessage} from './mock_message'; import {location, mockMessage} from './mock_message';
runInEachFileSystem(() => { runInEachFileSystem(() => {
let fs: FileSystem; let fs: PathManipulation;
beforeEach(() => fs = getFileSystem()); beforeEach(() => fs = getFileSystem());
describe('XmbTranslationSerializer', () => { describe('XmbTranslationSerializer', () => {
[false, true].forEach(useLegacyIds => { [false, true].forEach(useLegacyIds => {

View File

@ -5,7 +5,7 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {absoluteFrom, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; import {absoluteFrom, getFileSystem, PathManipulation} from '@angular/compiler-cli/src/ngtsc/file_system';
import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing'; import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing';
import {ɵmakeTemplateObject} from '@angular/localize'; import {ɵmakeTemplateObject} from '@angular/localize';
import {NodePath, TransformOptions, transformSync} from '@babel/core'; import {NodePath, TransformOptions, transformSync} from '@babel/core';
@ -16,7 +16,7 @@ import {Expression, Identifier, TaggedTemplateExpression, ExpressionStatement, C
import {isGlobalIdentifier, isNamedIdentifier, isStringLiteralArray, isArrayOfExpressions, unwrapStringLiteralArray, unwrapMessagePartsFromLocalizeCall, wrapInParensIfNecessary, buildLocalizeReplacement, unwrapSubstitutionsFromLocalizeCall, unwrapMessagePartsFromTemplateLiteral, getLocation} from '../src/source_file_utils'; import {isGlobalIdentifier, isNamedIdentifier, isStringLiteralArray, isArrayOfExpressions, unwrapStringLiteralArray, unwrapMessagePartsFromLocalizeCall, wrapInParensIfNecessary, buildLocalizeReplacement, unwrapSubstitutionsFromLocalizeCall, unwrapMessagePartsFromTemplateLiteral, getLocation} from '../src/source_file_utils';
runInEachFileSystem(() => { runInEachFileSystem(() => {
let fs: FileSystem; let fs: PathManipulation;
beforeEach(() => fs = getFileSystem()); beforeEach(() => fs = getFileSystem());
describe('utils', () => { describe('utils', () => {
describe('isNamedIdentifier()', () => { describe('isNamedIdentifier()', () => {

View File

@ -5,7 +5,6 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system';
import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing'; import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing';
import {ɵcomputeMsgId, ɵparseTranslation} from '@angular/localize'; import {ɵcomputeMsgId, ɵparseTranslation} from '@angular/localize';
import {ɵParsedTranslation} from '@angular/localize/private'; import {ɵParsedTranslation} from '@angular/localize/private';
@ -16,8 +15,6 @@ import {TranslatePluginOptions} from '../../../src/source_file_utils';
import {makeEs2015TranslatePlugin} from '../../../src/translate/source_files/es2015_translate_plugin'; import {makeEs2015TranslatePlugin} from '../../../src/translate/source_files/es2015_translate_plugin';
runInEachFileSystem(() => { runInEachFileSystem(() => {
let fs: FileSystem;
beforeEach(() => fs = getFileSystem());
describe('makeEs2015Plugin', () => { describe('makeEs2015Plugin', () => {
describe('(no translations)', () => { describe('(no translations)', () => {
it('should transform `$localize` tags with binary expression', () => { it('should transform `$localize` tags with binary expression', () => {

View File

@ -5,7 +5,6 @@
* Use of this source code is governed by an MIT-style license that can be * 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 * found in the LICENSE file at https://angular.io/license
*/ */
import {FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system';
import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing'; import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing';
import {ɵcomputeMsgId, ɵparseTranslation} from '@angular/localize'; import {ɵcomputeMsgId, ɵparseTranslation} from '@angular/localize';
import {ɵParsedTranslation} from '@angular/localize/private'; import {ɵParsedTranslation} from '@angular/localize/private';
@ -16,8 +15,6 @@ import {TranslatePluginOptions} from '../../../src/source_file_utils';
import {makeEs5TranslatePlugin} from '../../../src/translate/source_files/es5_translate_plugin'; import {makeEs5TranslatePlugin} from '../../../src/translate/source_files/es5_translate_plugin';
runInEachFileSystem(() => { runInEachFileSystem(() => {
let fs: FileSystem;
beforeEach(() => fs = getFileSystem());
describe('makeEs5Plugin', () => { describe('makeEs5Plugin', () => {
describe('(no translations)', () => { describe('(no translations)', () => {
it('should transform `$localize` calls with binary expression', () => { it('should transform `$localize` calls with binary expression', () => {