feat(compiler): DOM adapters + html5lib implementation; misc fixes
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import {List, Map, ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
|
||||
import {Element, DOM} from 'angular2/src/facade/dom';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
import {int, isBlank, isPresent, Type, StringJoiner, assertionsEnabled} from 'angular2/src/facade/lang';
|
||||
import {DirectiveMetadata} from '../directive_metadata';
|
||||
import {Decorator, Component, Viewport} from '../../annotations/annotations';
|
||||
@ -15,7 +15,7 @@ import {AST} from 'angular2/change_detection';
|
||||
* by the CompileSteps starting out with the pure HTMLElement.
|
||||
*/
|
||||
export class CompileElement {
|
||||
element:Element;
|
||||
element;
|
||||
_attrs:Map;
|
||||
_classList:List;
|
||||
textNodeBindings:Map;
|
||||
@ -40,7 +40,7 @@ export class CompileElement {
|
||||
ignoreBindings: boolean;
|
||||
elementDescription: string; // e.g. '<div [class]="foo">' : used to provide context in case of error
|
||||
|
||||
constructor(element:Element, compilationUnit = '') {
|
||||
constructor(element, compilationUnit = '') {
|
||||
this.element = element;
|
||||
this._attrs = null;
|
||||
this._classList = null;
|
||||
@ -177,7 +177,7 @@ export class CompileElement {
|
||||
|
||||
// return an HTML representation of an element start tag - without its content
|
||||
// this is used to give contextual information in case of errors
|
||||
function getElementDescription(domElement:Element):string {
|
||||
function getElementDescription(domElement):string {
|
||||
var buf = new StringJoiner();
|
||||
var atts = DOM.attributeMap(domElement);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {isPresent} from 'angular2/src/facade/lang';
|
||||
import {List, ListWrapper} from 'angular2/src/facade/collection';
|
||||
import {Element, DOM} from 'angular2/src/facade/dom';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
import {CompileElement} from './compile_element';
|
||||
import {CompileControl} from './compile_control';
|
||||
import {CompileStep} from './compile_step';
|
||||
@ -15,7 +15,7 @@ export class CompilePipeline {
|
||||
this._control = new CompileControl(steps);
|
||||
}
|
||||
|
||||
process(rootElement:Element, compilationCtxtDescription:string = ''):List {
|
||||
process(rootElement, compilationCtxtDescription:string = ''):List {
|
||||
var results = ListWrapper.create();
|
||||
this._process(results, null, new CompileElement(rootElement, compilationCtxtDescription), compilationCtxtDescription);
|
||||
return results;
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {isPresent, isBlank, BaseException, assertionsEnabled, RegExpWrapper} from 'angular2/src/facade/lang';
|
||||
import {List, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||
import {DOM} from 'angular2/src/facade/dom';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
import {SelectorMatcher} from '../selector';
|
||||
import {CssSelector} from '../selector';
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {int, isPresent, isBlank, Type, BaseException, StringWrapper, RegExpWrapper, isString, stringify} from 'angular2/src/facade/lang';
|
||||
import {Element, DOM, attrToPropMap} from 'angular2/src/facade/dom';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
import {ListWrapper, List, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||
|
||||
import {reflector} from 'angular2/src/reflection/reflection';
|
||||
@ -21,7 +21,7 @@ function ariaSetterFactory(attrName:string) {
|
||||
var setterFn = StringMapWrapper.get(ariaSettersCache, attrName);
|
||||
|
||||
if (isBlank(setterFn)) {
|
||||
setterFn = function(element:Element, value) {
|
||||
setterFn = function(element, value) {
|
||||
if (isPresent(value)) {
|
||||
DOM.setAttribute(element, attrName, stringify(value));
|
||||
} else {
|
||||
@ -42,7 +42,7 @@ function classSetterFactory(className:string) {
|
||||
var setterFn = StringMapWrapper.get(classSettersCache, className);
|
||||
|
||||
if (isBlank(setterFn)) {
|
||||
setterFn = function(element:Element, value) {
|
||||
setterFn = function(element, value) {
|
||||
if (value) {
|
||||
DOM.addClass(element, className);
|
||||
} else {
|
||||
@ -64,7 +64,7 @@ function styleSetterFactory(styleName:string, stylesuffix:string) {
|
||||
var setterFn = StringMapWrapper.get(styleSettersCache, cacheKey);
|
||||
|
||||
if (isBlank(setterFn)) {
|
||||
setterFn = function(element:Element, value) {
|
||||
setterFn = function(element, value) {
|
||||
var valAsStr;
|
||||
if (isPresent(value)) {
|
||||
valAsStr = stringify(value);
|
||||
@ -80,7 +80,7 @@ function styleSetterFactory(styleName:string, stylesuffix:string) {
|
||||
}
|
||||
|
||||
const ROLE_ATTR = 'role';
|
||||
function roleSetter(element:Element, value) {
|
||||
function roleSetter(element, value) {
|
||||
if (isString(value)) {
|
||||
DOM.setAttribute(element, ROLE_ATTR, value);
|
||||
} else {
|
||||
@ -92,18 +92,25 @@ function roleSetter(element:Element, value) {
|
||||
}
|
||||
|
||||
// special mapping for cases where attribute name doesn't match property name
|
||||
var attrToProp = StringMapWrapper.merge({
|
||||
"inner-html": "innerHTML",
|
||||
"readonly": "readOnly",
|
||||
"tabindex": "tabIndex",
|
||||
}, attrToPropMap);
|
||||
var _lazyAttrToProp;
|
||||
|
||||
function attrToProp() {
|
||||
if (!isPresent(_lazyAttrToProp)) {
|
||||
_lazyAttrToProp = StringMapWrapper.merge({
|
||||
"inner-html": "innerHTML",
|
||||
"readonly": "readOnly",
|
||||
"tabindex": "tabIndex",
|
||||
}, DOM.attrToPropMap);
|
||||
}
|
||||
return _lazyAttrToProp;
|
||||
}
|
||||
|
||||
// tells if an attribute is handled by the ElementBinderBuilder step
|
||||
export function isSpecialProperty(propName:string) {
|
||||
return StringWrapper.startsWith(propName, ARIA_PREFIX)
|
||||
|| StringWrapper.startsWith(propName, CLASS_PREFIX)
|
||||
|| StringWrapper.startsWith(propName, STYLE_PREFIX)
|
||||
|| StringMapWrapper.contains(attrToProp, propName);
|
||||
|| StringMapWrapper.contains(attrToProp(), propName);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -250,7 +257,7 @@ export class ElementBinderBuilder extends CompileStep {
|
||||
}
|
||||
|
||||
_resolvePropertyName(attrName:string) {
|
||||
var mappedPropName = StringMapWrapper.get(attrToProp, attrName);
|
||||
var mappedPropName = StringMapWrapper.get(attrToProp(), attrName);
|
||||
return isPresent(mappedPropName) ? mappedPropName : attrName;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import {isPresent} from 'angular2/src/facade/lang';
|
||||
import {MapWrapper} from 'angular2/src/facade/collection';
|
||||
import {DOM} from 'angular2/src/facade/dom';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
|
||||
import {CompileStep} from './compile_step';
|
||||
import {CompileElement} from './compile_element';
|
||||
|
@ -5,7 +5,7 @@ import {CompileControl} from './compile_control';
|
||||
import {DirectiveMetadata} from 'angular2/src/core/compiler/directive_metadata';
|
||||
import {ShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
|
||||
|
||||
import {DOM} from 'angular2/src/facade/dom';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
import {Type} from 'angular2/src/facade/lang';
|
||||
import {PromiseWrapper} from 'angular2/src/facade/async';
|
||||
import {ListWrapper} from 'angular2/src/facade/collection';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {RegExpWrapper, StringWrapper, isPresent} from 'angular2/src/facade/lang';
|
||||
import {DOM} from 'angular2/src/facade/dom';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
|
||||
import {Parser} from 'angular2/change_detection';
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {isBlank, isPresent, BaseException} from 'angular2/src/facade/lang';
|
||||
import {DOM, TemplateElement} from 'angular2/src/facade/dom';
|
||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||
import {MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
|
||||
|
||||
import {Parser} from 'angular2/change_detection';
|
||||
@ -64,8 +64,8 @@ export class ViewSplitter extends CompileStep {
|
||||
if (DOM.isTemplateElement(current.element)) {
|
||||
if (!current.isViewRoot) {
|
||||
var viewRoot = new CompileElement(DOM.createTemplate(''));
|
||||
var currentElement:TemplateElement = current.element;
|
||||
var viewRootElement:TemplateElement = viewRoot.element;
|
||||
var currentElement = current.element;
|
||||
var viewRootElement = viewRoot.element;
|
||||
this._moveChildNodes(DOM.content(currentElement), DOM.content(viewRootElement));
|
||||
// viewRoot doesn't appear in the original template, so we associate
|
||||
// the current element description to get a more meaningful message in case of error
|
||||
|
Reference in New Issue
Block a user