refactor(compiler): html_parser -> ml_parser

This commit is contained in:
Victor Berchet 2016-08-01 12:19:09 -07:00
parent fcafdff10b
commit cdb1a237e5
38 changed files with 72 additions and 74 deletions

View File

@ -14,7 +14,7 @@
import * as i18n from './src/i18n/index';
export {COMPILER_PROVIDERS, CompileDiDependencyMetadata, CompileDirectiveMetadata, CompileFactoryMetadata, CompileIdentifierMetadata, CompileMetadataWithIdentifier, CompilePipeMetadata, CompileProviderMetadata, CompileQueryMetadata, CompileTemplateMetadata, CompileTokenMetadata, CompileTypeMetadata, CompilerConfig, DEFAULT_PACKAGE_URL_PROVIDER, DirectiveResolver, NgModuleResolver, OfflineCompiler, PipeResolver, RenderTypes, RuntimeCompiler, SourceModule, TEMPLATE_TRANSFORMS, UrlResolver, XHR, analyzeAppProvidersForDeprecatedConfiguration, createOfflineCompileUrlResolver, platformCoreDynamic} from './src/compiler';
export {InterpolationConfig} from './src/html_parser/interpolation_config';
export {InterpolationConfig} from './src/ml_parser/interpolation_config';
export {ElementSchemaRegistry} from './src/schema/element_schema_registry';
export {i18n};

View File

@ -9,9 +9,9 @@
import * as directive_normalizer from './src/directive_normalizer';
import * as lexer from './src/expression_parser/lexer';
import * as parser from './src/expression_parser/parser';
import * as html_parser from './src/html_parser/html_parser';
import * as interpolation_config from './src/html_parser/interpolation_config';
import * as metadata_resolver from './src/metadata_resolver';
import * as html_parser from './src/ml_parser/html_parser';
import * as interpolation_config from './src/ml_parser/interpolation_config';
import * as ng_module_compiler from './src/ng_module_compiler';
import * as path_util from './src/output/path_util';
import * as ts_emitter from './src/output/ts_emitter';

View File

@ -24,7 +24,7 @@ export {NgModuleResolver} from './ng_module_resolver';
import {stringify} from './facade/lang';
import {ListWrapper} from './facade/collection';
import {TemplateParser} from './template_parser/template_parser';
import {HtmlParser} from './html_parser/html_parser';
import {HtmlParser} from './ml_parser/html_parser';
import {DirectiveNormalizer} from './directive_normalizer';
import {CompileMetadataResolver} from './metadata_resolver';
import {StyleCompiler} from './style_compiler';

View File

@ -13,9 +13,9 @@ import {CompilerConfig} from './config';
import {MapWrapper} from './facade/collection';
import {BaseException} from './facade/exceptions';
import {isBlank, isPresent} from './facade/lang';
import * as html from './html_parser/ast';
import {HtmlParser} from './html_parser/html_parser';
import {InterpolationConfig} from './html_parser/interpolation_config';
import * as html from './ml_parser/ast';
import {HtmlParser} from './ml_parser/html_parser';
import {InterpolationConfig} from './ml_parser/interpolation_config';
import {extractStyleUrls, isStyleUrlResolvable} from './style_url_resolver';
import {PreparsedElementType, preparseElement} from './template_parser/template_preparser';
import {UrlResolver} from './url_resolver';

View File

@ -9,10 +9,8 @@
import {Injectable} from '@angular/core';
import * as chars from '../chars';
import {ListWrapper} from '../facade/collection';
import {BaseException} from '../facade/exceptions';
import {StringWrapper, escapeRegExp, isBlank, isPresent} from '../facade/lang';
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../html_parser/interpolation_config';
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../ml_parser/interpolation_config';
import {AST, ASTWithSource, AstVisitor, Binary, BindingPipe, Chain, Conditional, EmptyExpr, FunctionCall, ImplicitReceiver, Interpolation, KeyedRead, KeyedWrite, LiteralArray, LiteralMap, LiteralPrimitive, MethodCall, ParseSpan, ParserError, PrefixNot, PropertyRead, PropertyWrite, Quote, SafeMethodCall, SafePropertyRead, TemplateBinding} from './ast';
import {EOF, Lexer, Token, TokenType, isIdentifier, isQuote} from './lexer';

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as html from '../html_parser/ast';
import * as html from '../ml_parser/ast';
import {I18nError} from './parse_util';
const _I18N_ATTR = 'i18n';

View File

@ -8,9 +8,9 @@
import {Lexer as ExpressionLexer} from '../expression_parser/lexer';
import {Parser as ExpressionParser} from '../expression_parser/parser';
import * as html from '../html_parser/ast';
import {getHtmlTagDefinition} from '../html_parser/html_tags';
import {InterpolationConfig} from '../html_parser/interpolation_config';
import * as html from '../ml_parser/ast';
import {getHtmlTagDefinition} from '../ml_parser/html_tags';
import {InterpolationConfig} from '../ml_parser/interpolation_config';
import {ParseSourceSpan} from '../parse_util';
import {extractAstMessages} from './extractor';

View File

@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {HtmlParser} from '../html_parser/html_parser';
import {InterpolationConfig} from '../html_parser/interpolation_config';
import {HtmlParser} from '../ml_parser/html_parser';
import {InterpolationConfig} from '../ml_parser/interpolation_config';
import {ParseError} from '../parse_util';
import * as i18n from './i18n_ast';

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as html from '../../html_parser/ast';
import * as html from '../../ml_parser/ast';
import * as i18n from '../i18n_ast';
export interface Serializer {

View File

@ -7,7 +7,7 @@
*/
import {ListWrapper} from '../../facade/collection';
import * as html from '../../html_parser/ast';
import * as html from '../../ml_parser/ast';
import * as i18n from '../i18n_ast';
import {Serializer} from './serializer';

View File

@ -6,10 +6,10 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as xml from '../../html_parser/ast';
import {HtmlParser} from '../../html_parser/html_parser';
import {InterpolationConfig} from '../../html_parser/interpolation_config';
import {XmlParser} from '../../html_parser/xml_parser';
import * as ml from '../../ml_parser/ast';
import {HtmlParser} from '../../ml_parser/html_parser';
import {InterpolationConfig} from '../../ml_parser/interpolation_config';
import {XmlParser} from '../../ml_parser/xml_parser';
import {ParseError} from '../../parse_util';
import * as i18n from '../i18n_ast';
import {I18nError} from '../parse_util';
@ -26,7 +26,7 @@ export class Xtb implements Serializer {
write(messageMap: {[id: string]: i18n.Message}): string { throw new Error('Unsupported'); }
load(content: string, url: string, placeholders: {[id: string]: {[name: string]: string}}):
{[id: string]: xml.Node[]} {
{[id: string]: ml.Node[]} {
// Parse the xtb file into xml nodes
const result = new XmlParser().parse(content, url);
@ -43,7 +43,7 @@ export class Xtb implements Serializer {
// Convert the string messages to html ast
// TODO(vicb): map error message back to the original message in xtb
let messageMap: {[id: string]: xml.Node[]} = {};
let messageMap: {[id: string]: ml.Node[]} = {};
let parseErrors: ParseError[] = [];
Object.keys(messages).forEach((id) => {
@ -60,7 +60,7 @@ export class Xtb implements Serializer {
}
}
class _Serializer implements xml.Visitor {
class _Serializer implements ml.Visitor {
private _messages: {[id: string]: string};
private _bundleDepth: number;
private _translationDepth: number;
@ -68,7 +68,7 @@ class _Serializer implements xml.Visitor {
private _placeholders: {[id: string]: {[name: string]: string}};
private _currentPlaceholders: {[name: string]: string};
parse(nodes: xml.Node[], _placeholders: {[id: string]: {[name: string]: string}}):
parse(nodes: ml.Node[], _placeholders: {[id: string]: {[name: string]: string}}):
{messages: {[k: string]: string}, errors: I18nError[]} {
this._messages = {};
this._bundleDepth = 0;
@ -76,19 +76,19 @@ class _Serializer implements xml.Visitor {
this._errors = [];
this._placeholders = _placeholders;
xml.visitAll(this, nodes, null);
ml.visitAll(this, nodes, null);
return {messages: this._messages, errors: this._errors};
}
visitElement(element: xml.Element, context: any): any {
visitElement(element: ml.Element, context: any): any {
switch (element.name) {
case _TRANSLATIONS_TAG:
this._bundleDepth++;
if (this._bundleDepth > 1) {
this._addError(element, `<${_TRANSLATIONS_TAG}> elements can not be nested`);
}
xml.visitAll(this, element.children, null);
ml.visitAll(this, element.children, null);
this._bundleDepth--;
break;
@ -102,7 +102,7 @@ class _Serializer implements xml.Visitor {
this._addError(element, `<${_TRANSLATION_TAG}> misses the "id" attribute`);
} else {
this._currentPlaceholders = this._placeholders[idAttr.value] || {};
this._messages[idAttr.value] = xml.visitAll(this, element.children).join('');
this._messages[idAttr.value] = ml.visitAll(this, element.children).join('');
}
this._translationDepth--;
break;
@ -125,25 +125,25 @@ class _Serializer implements xml.Visitor {
}
}
visitAttribute(attribute: xml.Attribute, context: any): any {
visitAttribute(attribute: ml.Attribute, context: any): any {
throw new Error('unreachable code');
}
visitText(text: xml.Text, context: any): any { return text.value; }
visitText(text: ml.Text, context: any): any { return text.value; }
visitComment(comment: xml.Comment, context: any): any { return ''; }
visitComment(comment: ml.Comment, context: any): any { return ''; }
visitExpansion(expansion: xml.Expansion, context: any): any {
visitExpansion(expansion: ml.Expansion, context: any): any {
const strCases = expansion.cases.map(c => c.visit(this, null));
return `{${expansion.switchValue}, ${expansion.type}, strCases.join(' ')}`;
}
visitExpansionCase(expansionCase: xml.ExpansionCase, context: any): any {
return `${expansionCase.value} {${xml.visitAll(this, expansionCase.expression, null)}}`;
visitExpansionCase(expansionCase: ml.ExpansionCase, context: any): any {
return `${expansionCase.value} {${ml.visitAll(this, expansionCase.expression, null)}}`;
}
private _addError(node: xml.Node, message: string): void {
private _addError(node: ml.Node, message: string): void {
this._errors.push(new I18nError(node.sourceSpan, message));
}
}

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as html from '../html_parser/ast';
import * as html from '../ml_parser/ast';
import {Serializer} from './serializers/serializer';

View File

@ -15,11 +15,11 @@ import {Parser} from '../expression_parser/parser';
import {ListWrapper, SetWrapper, StringMapWrapper} from '../facade/collection';
import {BaseException} from '../facade/exceptions';
import {isBlank, isPresent} from '../facade/lang';
import * as html from '../html_parser/ast';
import {HtmlParser, ParseTreeResult} from '../html_parser/html_parser';
import {expandNodes} from '../html_parser/icu_ast_expander';
import {InterpolationConfig} from '../html_parser/interpolation_config';
import {mergeNsAndName, splitNsName} from '../html_parser/tags';
import * as html from '../ml_parser/ast';
import {HtmlParser, ParseTreeResult} from '../ml_parser/html_parser';
import {expandNodes} from '../ml_parser/icu_ast_expander';
import {InterpolationConfig} from '../ml_parser/interpolation_config';
import {mergeNsAndName, splitNsName} from '../ml_parser/tags';
import {Identifiers, identifierToken} from '../identifiers';
import {ParseError, ParseErrorLevel, ParseSourceSpan} from '../parse_util';
import {ProviderElementContext, ProviderViewContext} from '../provider_analyzer';

View File

@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import * as html from '../html_parser/ast';
import {splitNsName} from '../html_parser/tags';
import * as html from '../ml_parser/ast';
import {splitNsName} from '../ml_parser/tags';
const NG_CONTENT_SELECT_ATTR = 'select';
const NG_CONTENT_ELEMENT = 'ng-content';

View File

@ -8,7 +8,7 @@
import {AST, AstVisitor, Binary, BindingPipe, Chain, Conditional, EmptyExpr, FunctionCall, ImplicitReceiver, Interpolation, KeyedRead, KeyedWrite, LiteralArray, LiteralMap, LiteralPrimitive, MethodCall, PrefixNot, PropertyRead, PropertyWrite, Quote, SafeMethodCall, SafePropertyRead} from '../../src/expression_parser/ast';
import {StringWrapper, isPresent, isString} from '../../src/facade/lang';
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../../src/html_parser/interpolation_config';
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../../src/ml_parser/interpolation_config';
class Unparser implements AstVisitor {
private static _quoteRegExp = /"/g;

View File

@ -9,7 +9,7 @@
import {ExtractionResult, extractAstMessages} from '@angular/compiler/src/i18n/extractor';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {HtmlParser} from '../../src/html_parser/html_parser';
import {HtmlParser} from '../../src/ml_parser/html_parser';
import {serializeAst} from '../html_parser/ast_serializer_spec';
export function main() {

View File

@ -10,9 +10,9 @@ import {Message} from '@angular/compiler/src/i18n/i18n_ast';
import {extractI18nMessages} from '@angular/compiler/src/i18n/i18n_parser';
import {ddescribe, describe, expect, it} from '@angular/core/testing/testing_internal';
import {HtmlParser} from '../../src/html_parser/html_parser';
import {DEFAULT_INTERPOLATION_CONFIG} from '../../src/html_parser/interpolation_config';
import {serializeAst} from '../../src/i18n/message_bundle';
import {HtmlParser} from '../../src/ml_parser/html_parser';
import {DEFAULT_INTERPOLATION_CONFIG} from '../../src/ml_parser/interpolation_config';
export function main() {
describe('I18nParser', () => {

View File

@ -10,9 +10,9 @@ import * as i18n from '@angular/compiler/src/i18n/i18n_ast';
import {Serializer} from '@angular/compiler/src/i18n/serializers/serializer';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {HtmlParser} from '../../src/html_parser/html_parser';
import {DEFAULT_INTERPOLATION_CONFIG} from '../../src/html_parser/interpolation_config';
import {MessageBundle, serializeAst, strHash} from '../../src/i18n/message_bundle';
import {HtmlParser} from '../../src/ml_parser/html_parser';
import {DEFAULT_INTERPOLATION_CONFIG} from '../../src/ml_parser/interpolation_config';
export function main(): void {
describe('MessageBundle', () => {

View File

@ -9,9 +9,9 @@
import {Xmb} from '@angular/compiler/src/i18n/serializers/xmb';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {HtmlParser} from '../../../src/html_parser/html_parser';
import {DEFAULT_INTERPOLATION_CONFIG} from '../../../src/html_parser/interpolation_config';
import {MessageBundle} from '../../../src/i18n/message_bundle';
import {HtmlParser} from '../../../src/ml_parser/html_parser';
import {DEFAULT_INTERPOLATION_CONFIG} from '../../../src/ml_parser/interpolation_config';
export function main(): void {
describe('XMB serializer', () => {

View File

@ -10,9 +10,9 @@ import {Xtb} from '@angular/compiler/src/i18n/serializers/xtb';
import {escapeRegExp} from '@angular/core/src/facade/lang';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {HtmlParser} from '../../../src/html_parser/html_parser';
import {DEFAULT_INTERPOLATION_CONFIG} from '../../../src/html_parser/interpolation_config';
import {serializeAst} from '../../html_parser/ast_serializer_spec';
import {HtmlParser} from '../../../src/ml_parser/html_parser';
import {DEFAULT_INTERPOLATION_CONFIG} from '../../../src/ml_parser/interpolation_config';
import {serializeAst} from '../../ml_parser/ast_serializer_spec';
export function main(): void {
describe('XTB serializer', () => {

View File

@ -7,8 +7,8 @@
*/
import {beforeEach, ddescribe, describe, expect, it} from '../../../core/testing/testing_internal';
import * as html from '../../src/html_parser/ast';
import {HtmlParser} from '../../src/html_parser/html_parser';
import * as html from '../../src/ml_parser/ast';
import {HtmlParser} from '../../src/ml_parser/html_parser';
export function main() {
describe('Node serilaizer', () => {

View File

@ -7,8 +7,8 @@
*/
import {BaseException} from '../../src/facade/exceptions';
import * as html from '../../src/html_parser/ast';
import {ParseTreeResult} from '../../src/html_parser/html_parser';
import * as html from '../../src/ml_parser/ast';
import {ParseTreeResult} from '../../src/ml_parser/html_parser';
import {ParseLocation} from '../../src/parse_util';
export function humanizeDom(parseResult: ParseTreeResult, addSourceSpan: boolean = false): any[] {

View File

@ -7,9 +7,9 @@
*/
import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '../../../core/testing/testing_internal';
import * as html from '../../src/html_parser/ast';
import {HtmlParser, ParseTreeResult, TreeError} from '../../src/html_parser/html_parser';
import {TokenType} from '../../src/html_parser/lexer';
import * as html from '../../src/ml_parser/ast';
import {HtmlParser, ParseTreeResult, TreeError} from '../../src/ml_parser/html_parser';
import {TokenType} from '../../src/ml_parser/lexer';
import {ParseError} from '../../src/parse_util';
import {humanizeDom, humanizeDomSourceSpans, humanizeLineColumn} from './ast_spec_utils';

View File

@ -7,9 +7,9 @@
*/
import {ddescribe, describe, expect, iit, it} from '../../../core/testing/testing_internal';
import * as html from '../../src/html_parser/ast';
import {HtmlParser} from '../../src/html_parser/html_parser';
import {ExpansionResult, expandNodes} from '../../src/html_parser/icu_ast_expander';
import * as html from '../../src/ml_parser/ast';
import {HtmlParser} from '../../src/ml_parser/html_parser';
import {ExpansionResult, expandNodes} from '../../src/ml_parser/icu_ast_expander';
import {ParseError} from '../../src/parse_util';
import {humanizeNodes} from './ast_spec_utils';

View File

@ -7,9 +7,9 @@
*/
import {afterEach, beforeEach, ddescribe, describe, expect, iit, it, xit} from '../../../core/testing/testing_internal';
import {getHtmlTagDefinition} from '../../src/html_parser/html_tags';
import {InterpolationConfig} from '../../src/html_parser/interpolation_config';
import * as lex from '../../src/html_parser/lexer';
import {getHtmlTagDefinition} from '../../src/ml_parser/html_tags';
import {InterpolationConfig} from '../../src/ml_parser/interpolation_config';
import * as lex from '../../src/ml_parser/lexer';
import {ParseLocation, ParseSourceFile, ParseSourceSpan} from '../../src/parse_util';
export function main() {

View File

@ -11,8 +11,8 @@ import {CUSTOM_ELEMENTS_SCHEMA, SecurityContext} from '@angular/core';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {browserDetection} from '@angular/platform-browser/testing/browser_util';
import {Element} from '../../src/html_parser/ast';
import {HtmlParser} from '../../src/html_parser/html_parser';
import {Element} from '../../src/ml_parser/ast';
import {HtmlParser} from '../../src/ml_parser/html_parser';
import {extractSchema} from './schema_extractor';

View File

@ -17,8 +17,8 @@ import {Console} from '@angular/core/src/console';
import {TestBed} from '@angular/core/testing';
import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xit} from '@angular/core/testing/testing_internal';
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../../src/html_parser/interpolation_config';
import {Identifiers, identifierToken} from '../../src/identifiers';
import {DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig} from '../../src/ml_parser/interpolation_config';
import {unparse} from '../expression_parser/unparser';
import {TEST_COMPILER_PROVIDERS} from '../test_bindings';

View File

@ -7,8 +7,8 @@
*/
import {afterEach, beforeEach, beforeEachProviders, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '../../../core/testing/testing_internal';
import {Element} from '../../src/html_parser/ast';
import {HtmlParser} from '../../src/html_parser/html_parser';
import {Element} from '../../src/ml_parser/ast';
import {HtmlParser} from '../../src/ml_parser/html_parser';
import {PreparsedElement, PreparsedElementType, preparseElement} from '../../src/template_parser/template_preparser';
export function main() {