mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
- Rename `DirectiveMetadata` into `CompileDirectiveMetadata`, merge with `NormalizedDirectiveMetadata` and remove `ChangeDetectionMetadata` - Store change detector factories not as array but directly at the `CompiledTemplate` or the embedded template to make instantiation easier later on - Already analyze variable values and map them to `Directive.exportAs` - Keep the directive sort order as specified in the `@View()` annotation - Allow to clear the runtime cache in `StyleCompiler` and `TemplateCompiler` - Ignore `script` elements to match the semantics of the current compiler - Make all components dynamically loadable and remove the previously introduced property `@Component#dynamicLoadable` for now until we find a better option to configure this - Don’t allow to specify bindings in `@View#directives` and `@View#pipes` as this was never supported by the transformer (see below for the breaking change) BREAKING CHANGE: - don't support DI bindings in `@View#directives` and `@View@pipes` any more in preparation of integrating the new compiler. Use `@Directive#bindings` to reexport directives under a different token instead. Part of #3605 Closes #4314
84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import {StringWrapper, isBlank, isJsObject} from 'angular2/src/core/facade/lang';
|
|
|
|
var CAMEL_CASE_REGEXP = /([A-Z])/g;
|
|
var DASH_CASE_REGEXP = /-([a-z])/g;
|
|
var SINGLE_QUOTE_ESCAPE_STRING_RE = /'|\\|\n/g;
|
|
var DOUBLE_QUOTE_ESCAPE_STRING_RE = /"|\\|\n/g;
|
|
|
|
export var IS_DART = !isJsObject({});
|
|
|
|
export function camelCaseToDashCase(input: string): string {
|
|
return StringWrapper.replaceAllMapped(input, CAMEL_CASE_REGEXP,
|
|
(m) => { return '-' + m[1].toLowerCase(); });
|
|
}
|
|
|
|
export function dashCaseToCamelCase(input: string): string {
|
|
return StringWrapper.replaceAllMapped(input, DASH_CASE_REGEXP,
|
|
(m) => { return m[1].toUpperCase(); });
|
|
}
|
|
|
|
export function escapeSingleQuoteString(input: string): string {
|
|
if (isBlank(input)) {
|
|
return null;
|
|
}
|
|
return `'${escapeString(input, SINGLE_QUOTE_ESCAPE_STRING_RE)}'`;
|
|
}
|
|
|
|
export function escapeDoubleQuoteString(input: string): string {
|
|
if (isBlank(input)) {
|
|
return null;
|
|
}
|
|
return `"${escapeString(input, DOUBLE_QUOTE_ESCAPE_STRING_RE)}"`;
|
|
}
|
|
|
|
function escapeString(input: string, re: RegExp): string {
|
|
return StringWrapper.replaceAllMapped(input, re, (match) => {
|
|
if (match[0] == '\n') {
|
|
return '\\n';
|
|
} else {
|
|
return `\\${match[0]}`;
|
|
}
|
|
});
|
|
}
|
|
|
|
export function codeGenExportVariable(name: string): string {
|
|
return IS_DART ? `var ${name} = ` : `var ${name} = exports['${name}'] = `;
|
|
}
|
|
|
|
export function codeGenConcatArray(expression: string): string {
|
|
return `${IS_DART ? '..addAll' : '.concat'}(${expression})`;
|
|
}
|
|
|
|
export function codeGenMapArray(argNames: string[], callback: string): string {
|
|
if (IS_DART) {
|
|
return `.map( (${argNames.join(',')}) => ${callback} ).toList()`;
|
|
} else {
|
|
return `.map(function(${argNames.join(',')}) { return ${callback}; })`;
|
|
}
|
|
}
|
|
|
|
export function codeGenReplaceAll(pattern: string, value: string): string {
|
|
if (IS_DART) {
|
|
return `.replaceAll('${pattern}', '${value}')`;
|
|
} else {
|
|
return `.replace(/${pattern}/g, '${value}')`;
|
|
}
|
|
}
|
|
|
|
export function codeGenValueFn(params: string[], value: string): string {
|
|
if (IS_DART) {
|
|
return `(${params.join(',')}) => ${value}`;
|
|
} else {
|
|
return `function(${params.join(',')}) { return ${value}; }`;
|
|
}
|
|
}
|
|
|
|
|
|
export function splitAtColon(input: string, defaultValues: string[]): string[] {
|
|
var parts = StringWrapper.split(input.trim(), /\s*:\s*/g);
|
|
if (parts.length > 1) {
|
|
return parts;
|
|
} else {
|
|
return defaultValues;
|
|
}
|
|
}
|