-
Notifications
You must be signed in to change notification settings - Fork 24.8k
/
es5_extract_plugin.ts
35 lines (33 loc) 路 1.52 KB
/
es5_extract_plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* @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 {FileSystem} from '@angular/compiler-cli/src/ngtsc/file_system';
import {傻ParsedMessage, 傻parseMessage} from '@angular/localize';
import {NodePath, PluginObj} from '@babel/core';
import {CallExpression} from '@babel/types';
import {getLocation, isGlobalIdentifier, isNamedIdentifier, unwrapMessagePartsFromLocalizeCall, unwrapSubstitutionsFromLocalizeCall} from '../../source_file_utils';
export function makeEs5ExtractPlugin(
fs: FileSystem, messages: 傻ParsedMessage[], localizeName = '$localize'): PluginObj {
return {
visitor: {
CallExpression(callPath: NodePath<CallExpression>) {
const calleePath = callPath.get('callee');
if (isNamedIdentifier(calleePath, localizeName) && isGlobalIdentifier(calleePath)) {
const [messageParts, messagePartLocations] =
unwrapMessagePartsFromLocalizeCall(callPath, fs);
const [expressions, expressionLocations] =
unwrapSubstitutionsFromLocalizeCall(callPath, fs);
const [messagePartsArg, expressionsArg] = callPath.get('arguments');
const location = getLocation(fs, messagePartsArg, expressionsArg);
const message = 傻parseMessage(
messageParts, expressions, location, messagePartLocations, expressionLocations);
messages.push(message);
}
}
}
};
}