Skip to content

Commit 757eae8

Browse files
committed
feat(compiler): DOM adapters + html5lib implementation; misc fixes
1 parent ab42664 commit 757eae8

File tree

79 files changed

+1223
-643
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1223
-643
lines changed

gulpfile.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,19 +618,31 @@ gulp.task('tests/transform.dart', function() {
618618
.pipe(gulp.dest('dist/dart/angular2/test/transform'));
619619
});
620620

621+
622+
621623
// -----------------
622624
// orchestrated targets
623-
gulp.task('build.dart', function(done) {
625+
626+
// Builds all Dart packages, but does not compile them
627+
gulp.task('build/packages.dart', function(done) {
624628
runSequence(
625629
['build/transpile.dart', 'build/html.dart', 'build/copy.dart', 'build/multicopy.dart'],
626630
'tests/transform.dart',
627631
'build/format.dart',
628632
'build/pubspec.dart',
633+
done
634+
);
635+
});
636+
637+
// Builds and compiles all Dart packages
638+
gulp.task('build.dart', function(done) {
639+
runSequence(
640+
'build/packages.dart',
641+
'build/analyze.dart',
629642
'build/pubbuild.dart',
630643
// Note: pubbuild.dart will clear the dart2js folder, so we need to copy
631644
// our files after this :-(
632645
'build/multicopy.js.dart2js',
633-
'build/analyze.dart',
634646
done
635647
);
636648
});

modules/angular2/e2e_test/test_util.es6

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ function verifyNoBrowserErrors() {
1717
browser.executeScript('1+1');
1818
browser.manage().logs().get('browser').then(function(browserLog) {
1919
var filteredLog = browserLog.filter(function(logEntry) {
20+
console.log('>> ' + require('util').inspect(logEntry));
2021
return logEntry.level.value > webdriver.logging.Level.WARNING.value;
2122
});
2223
expect(filteredLog.length).toEqual(0);
23-
if (filteredLog.length) {
24-
console.log('browser console errors: ' + require('util').inspect(filteredLog));
25-
}
2624
});
2725
}
2826

modules/angular2/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies:
1313
barback: '^0.15.2+2'
1414
code_transformers: '^0.2.5'
1515
dart_style: '^0.1.3'
16+
html5lib: '^0.12.0'
1617
stack_trace: '^1.1.1'
1718
dev_dependencies:
1819
guinness: "^0.1.16"

modules/angular2/src/core/application.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Injector, bind, OpaqueToken} from 'angular2/di';
22
import {Type, FIELD, isBlank, isPresent, BaseException, assertionsEnabled, print} from 'angular2/src/facade/lang';
3-
import {DOM, Element} from 'angular2/src/facade/dom';
3+
import {BrowserDomAdapter} from 'angular2/src/dom/browser_adapter';
4+
import {DOM} from 'angular2/src/dom/dom_adapter';
45
import {Compiler, CompilerCache} from './compiler/compiler';
56
import {ProtoView} from './compiler/view';
67
import {Reflector, reflector} from 'angular2/src/reflection/reflection';
@@ -117,6 +118,7 @@ function _createVmZone(givenReporter:Function): VmTurnZone {
117118
// Multiple calls to this method are allowed. Each application would only share
118119
// _rootInjector, which is not user-configurable by design, thus safe to share.
119120
export function bootstrap(appComponentType: Type, bindings: List<Binding>=null, givenBootstrapErrorReporter: Function=null): Promise {
121+
BrowserDomAdapter.makeCurrent();
120122
var bootstrapProcess = PromiseWrapper.completer();
121123

122124
var zone = _createVmZone(givenBootstrapErrorReporter);

modules/angular2/src/core/compiler/compiler.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {Type, isBlank, isPresent, BaseException, normalizeBlank, stringify} from 'angular2/src/facade/lang';
22
import {Promise, PromiseWrapper} from 'angular2/src/facade/async';
33
import {List, ListWrapper, Map, MapWrapper} from 'angular2/src/facade/collection';
4-
import {DOM, Element} from 'angular2/src/facade/dom';
54

65
import {ChangeDetection, Parser} from 'angular2/change_detection';
76

@@ -149,7 +148,7 @@ export class Compiler {
149148
}
150149

151150
// TODO(vicb): union type return ProtoView or Promise<ProtoView>
152-
_compileTemplate(template: Template, tplElement: Element, component: Type) {
151+
_compileTemplate(template: Template, tplElement, component: Type) {
153152
var pipeline = new CompilePipeline(this.createSteps(component, template));
154153
var compilationCtxtDescription = stringify(this._reader.read(component).type);
155154
var compileElements;

modules/angular2/src/core/compiler/pipeline/compile_element.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {List, Map, ListWrapper, MapWrapper} from 'angular2/src/facade/collection';
2-
import {Element, DOM} from 'angular2/src/facade/dom';
2+
import {DOM} from 'angular2/src/dom/dom_adapter';
33
import {int, isBlank, isPresent, Type, StringJoiner, assertionsEnabled} from 'angular2/src/facade/lang';
44
import {DirectiveMetadata} from '../directive_metadata';
55
import {Decorator, Component, Viewport} from '../../annotations/annotations';
@@ -15,7 +15,7 @@ import {AST} from 'angular2/change_detection';
1515
* by the CompileSteps starting out with the pure HTMLElement.
1616
*/
1717
export class CompileElement {
18-
element:Element;
18+
element;
1919
_attrs:Map;
2020
_classList:List;
2121
textNodeBindings:Map;
@@ -40,7 +40,7 @@ export class CompileElement {
4040
ignoreBindings: boolean;
4141
elementDescription: string; // e.g. '<div [class]="foo">' : used to provide context in case of error
4242

43-
constructor(element:Element, compilationUnit = '') {
43+
constructor(element, compilationUnit = '') {
4444
this.element = element;
4545
this._attrs = null;
4646
this._classList = null;
@@ -177,7 +177,7 @@ export class CompileElement {
177177

178178
// return an HTML representation of an element start tag - without its content
179179
// this is used to give contextual information in case of errors
180-
function getElementDescription(domElement:Element):string {
180+
function getElementDescription(domElement):string {
181181
var buf = new StringJoiner();
182182
var atts = DOM.attributeMap(domElement);
183183

modules/angular2/src/core/compiler/pipeline/compile_pipeline.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {isPresent} from 'angular2/src/facade/lang';
22
import {List, ListWrapper} from 'angular2/src/facade/collection';
3-
import {Element, DOM} from 'angular2/src/facade/dom';
3+
import {DOM} from 'angular2/src/dom/dom_adapter';
44
import {CompileElement} from './compile_element';
55
import {CompileControl} from './compile_control';
66
import {CompileStep} from './compile_step';
@@ -15,7 +15,7 @@ export class CompilePipeline {
1515
this._control = new CompileControl(steps);
1616
}
1717

18-
process(rootElement:Element, compilationCtxtDescription:string = ''):List {
18+
process(rootElement, compilationCtxtDescription:string = ''):List {
1919
var results = ListWrapper.create();
2020
this._process(results, null, new CompileElement(rootElement, compilationCtxtDescription), compilationCtxtDescription);
2121
return results;

modules/angular2/src/core/compiler/pipeline/directive_parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {isPresent, isBlank, BaseException, assertionsEnabled, RegExpWrapper} from 'angular2/src/facade/lang';
22
import {List, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
3-
import {DOM} from 'angular2/src/facade/dom';
3+
import {DOM} from 'angular2/src/dom/dom_adapter';
44
import {SelectorMatcher} from '../selector';
55
import {CssSelector} from '../selector';
66

modules/angular2/src/core/compiler/pipeline/element_binder_builder.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {int, isPresent, isBlank, Type, BaseException, StringWrapper, RegExpWrapper, isString, stringify} from 'angular2/src/facade/lang';
2-
import {Element, DOM, attrToPropMap} from 'angular2/src/facade/dom';
2+
import {DOM} from 'angular2/src/dom/dom_adapter';
33
import {ListWrapper, List, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
44

55
import {reflector} from 'angular2/src/reflection/reflection';
@@ -21,7 +21,7 @@ function ariaSetterFactory(attrName:string) {
2121
var setterFn = StringMapWrapper.get(ariaSettersCache, attrName);
2222

2323
if (isBlank(setterFn)) {
24-
setterFn = function(element:Element, value) {
24+
setterFn = function(element, value) {
2525
if (isPresent(value)) {
2626
DOM.setAttribute(element, attrName, stringify(value));
2727
} else {
@@ -42,7 +42,7 @@ function classSetterFactory(className:string) {
4242
var setterFn = StringMapWrapper.get(classSettersCache, className);
4343

4444
if (isBlank(setterFn)) {
45-
setterFn = function(element:Element, value) {
45+
setterFn = function(element, value) {
4646
if (value) {
4747
DOM.addClass(element, className);
4848
} else {
@@ -64,7 +64,7 @@ function styleSetterFactory(styleName:string, stylesuffix:string) {
6464
var setterFn = StringMapWrapper.get(styleSettersCache, cacheKey);
6565

6666
if (isBlank(setterFn)) {
67-
setterFn = function(element:Element, value) {
67+
setterFn = function(element, value) {
6868
var valAsStr;
6969
if (isPresent(value)) {
7070
valAsStr = stringify(value);
@@ -80,7 +80,7 @@ function styleSetterFactory(styleName:string, stylesuffix:string) {
8080
}
8181

8282
const ROLE_ATTR = 'role';
83-
function roleSetter(element:Element, value) {
83+
function roleSetter(element, value) {
8484
if (isString(value)) {
8585
DOM.setAttribute(element, ROLE_ATTR, value);
8686
} else {
@@ -92,18 +92,25 @@ function roleSetter(element:Element, value) {
9292
}
9393

9494
// special mapping for cases where attribute name doesn't match property name
95-
var attrToProp = StringMapWrapper.merge({
96-
"inner-html": "innerHTML",
97-
"readonly": "readOnly",
98-
"tabindex": "tabIndex",
99-
}, attrToPropMap);
95+
var _lazyAttrToProp;
96+
97+
function attrToProp() {
98+
if (!isPresent(_lazyAttrToProp)) {
99+
_lazyAttrToProp = StringMapWrapper.merge({
100+
"inner-html": "innerHTML",
101+
"readonly": "readOnly",
102+
"tabindex": "tabIndex",
103+
}, DOM.attrToPropMap);
104+
}
105+
return _lazyAttrToProp;
106+
}
100107

101108
// tells if an attribute is handled by the ElementBinderBuilder step
102109
export function isSpecialProperty(propName:string) {
103110
return StringWrapper.startsWith(propName, ARIA_PREFIX)
104111
|| StringWrapper.startsWith(propName, CLASS_PREFIX)
105112
|| StringWrapper.startsWith(propName, STYLE_PREFIX)
106-
|| StringMapWrapper.contains(attrToProp, propName);
113+
|| StringMapWrapper.contains(attrToProp(), propName);
107114
}
108115

109116
/**
@@ -250,7 +257,7 @@ export class ElementBinderBuilder extends CompileStep {
250257
}
251258

252259
_resolvePropertyName(attrName:string) {
253-
var mappedPropName = StringMapWrapper.get(attrToProp, attrName);
260+
var mappedPropName = StringMapWrapper.get(attrToProp(), attrName);
254261
return isPresent(mappedPropName) ? mappedPropName : attrName;
255262
}
256263
}

modules/angular2/src/core/compiler/pipeline/element_binding_marker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {isPresent} from 'angular2/src/facade/lang';
22
import {MapWrapper} from 'angular2/src/facade/collection';
3-
import {DOM} from 'angular2/src/facade/dom';
3+
import {DOM} from 'angular2/src/dom/dom_adapter';
44

55
import {CompileStep} from './compile_step';
66
import {CompileElement} from './compile_element';

modules/angular2/src/core/compiler/pipeline/resolve_css.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {CompileControl} from './compile_control';
55
import {DirectiveMetadata} from 'angular2/src/core/compiler/directive_metadata';
66
import {ShadowDomStrategy} from 'angular2/src/core/compiler/shadow_dom_strategy';
77

8-
import {DOM} from 'angular2/src/facade/dom';
8+
import {DOM} from 'angular2/src/dom/dom_adapter';
99
import {Type} from 'angular2/src/facade/lang';
1010
import {PromiseWrapper} from 'angular2/src/facade/async';
1111
import {ListWrapper} from 'angular2/src/facade/collection';

modules/angular2/src/core/compiler/pipeline/text_interpolation_parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {RegExpWrapper, StringWrapper, isPresent} from 'angular2/src/facade/lang';
2-
import {DOM} from 'angular2/src/facade/dom';
2+
import {DOM} from 'angular2/src/dom/dom_adapter';
33

44
import {Parser} from 'angular2/change_detection';
55

modules/angular2/src/core/compiler/pipeline/view_splitter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {isBlank, isPresent, BaseException} from 'angular2/src/facade/lang';
2-
import {DOM, TemplateElement} from 'angular2/src/facade/dom';
2+
import {DOM} from 'angular2/src/dom/dom_adapter';
33
import {MapWrapper, ListWrapper} from 'angular2/src/facade/collection';
44

55
import {Parser} from 'angular2/change_detection';
@@ -64,8 +64,8 @@ export class ViewSplitter extends CompileStep {
6464
if (DOM.isTemplateElement(current.element)) {
6565
if (!current.isViewRoot) {
6666
var viewRoot = new CompileElement(DOM.createTemplate(''));
67-
var currentElement:TemplateElement = current.element;
68-
var viewRootElement:TemplateElement = viewRoot.element;
67+
var currentElement = current.element;
68+
var viewRootElement = viewRoot.element;
6969
this._moveChildNodes(DOM.content(currentElement), DOM.content(viewRootElement));
7070
// viewRoot doesn't appear in the original template, so we associate
7171
// the current element description to get a more meaningful message in case of error

modules/angular2/src/core/compiler/shadow_dom_emulation/content_tag.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import {Decorator} from '../../annotations/annotations';
22
import {SourceLightDom, DestinationLightDom, LightDom} from './light_dom';
33
import {Inject} from 'angular2/di';
4-
import {Element, Node, DOM} from 'angular2/src/facade/dom';
4+
import {DOM} from 'angular2/src/dom/dom_adapter';
55
import {isPresent} from 'angular2/src/facade/lang';
66
import {List, ListWrapper} from 'angular2/src/facade/collection';
77
import {NgElement} from 'angular2/src/core/dom/element';
88

9-
var _scriptTemplate = DOM.createScriptTag('type', 'ng/content')
10-
119
class ContentStrategy {
12-
nodes: List<Node>;
13-
insert(nodes:List<Node>){}
10+
nodes:List;
11+
insert(nodes:List){}
1412
}
1513

1614
/**
@@ -19,34 +17,42 @@ class ContentStrategy {
1917
* and thus does not affect redistribution.
2018
*/
2119
class RenderedContent extends ContentStrategy {
22-
beginScript:Element;
23-
endScript:Element;
20+
static _lazyScriptTemplate;
21+
beginScript;
22+
endScript;
2423

25-
constructor(contentEl:Element) {
24+
constructor(contentEl) {
2625
super();
2726
this._replaceContentElementWithScriptTags(contentEl);
2827
this.nodes = [];
2928
}
3029

30+
_scriptTemplate() {
31+
if (!isPresent(RenderedContent._lazyScriptTemplate)) {
32+
RenderedContent._lazyScriptTemplate = DOM.createScriptTag('type', 'ng/content');
33+
}
34+
return RenderedContent._lazyScriptTemplate;
35+
}
36+
3137
// Inserts the nodes in between the start and end scripts.
3238
// Previous content is removed.
33-
insert(nodes:List<Node>) {
39+
insert(nodes:List) {
3440
this.nodes = nodes;
3541
DOM.insertAllBefore(this.endScript, nodes);
3642
this._removeNodesUntil(ListWrapper.isEmpty(nodes) ? this.endScript : nodes[0]);
3743
}
3844

3945
// Replaces the content tag with a pair of script tags
40-
_replaceContentElementWithScriptTags(contentEl:Element) {
41-
this.beginScript = DOM.clone(_scriptTemplate);
42-
this.endScript = DOM.clone(_scriptTemplate);
46+
_replaceContentElementWithScriptTags(contentEl) {
47+
this.beginScript = DOM.clone(this._scriptTemplate());
48+
this.endScript = DOM.clone(this._scriptTemplate());
4349

4450
DOM.insertBefore(contentEl, this.beginScript);
4551
DOM.insertBefore(contentEl, this.endScript);
4652
DOM.removeChild(DOM.parentElement(contentEl), contentEl);
4753
}
4854

49-
_removeNodesUntil(node:Node) {
55+
_removeNodesUntil(node) {
5056
var p = DOM.parentElement(this.beginScript);
5157
for (var next = DOM.nextSibling(this.beginScript);
5258
next !== node;
@@ -70,7 +76,7 @@ class IntermediateContent extends ContentStrategy {
7076
this.nodes = [];
7177
}
7278

73-
insert(nodes:List<Node>) {
79+
insert(nodes:List) {
7480
this.nodes = nodes;
7581
this.destinationLightDom.redistribute();
7682
}
@@ -91,11 +97,11 @@ export class Content {
9197
new RenderedContent(contentEl.domElement);
9298
}
9399

94-
nodes():List<Node> {
100+
nodes():List {
95101
return this._strategy.nodes;
96102
}
97103

98-
insert(nodes:List<Node>) {
104+
insert(nodes:List) {
99105
this._strategy.insert(nodes);
100106
}
101107
}

0 commit comments

Comments
 (0)