Skip to content

Commit 8f801a3

Browse files
committed
fix(bundling) Remove parse5 dependency.
Delete the parse5_adapter module. Create a dummy DOM adapter and register it for that code (*cough* @angular/router *cough*) that logs diagnostic messages via the DOM adapter. Register the DOM adapter dynamically, if and only if you can discover @angular/platform-browser. Hopefully one day @angular/router and @angular/http won't import @angular/platform-browser and we can strip it from the release bundle completely.
1 parent 4ac822d commit 8f801a3

File tree

5 files changed

+222
-831
lines changed

5 files changed

+222
-831
lines changed

Diff for: nativescript-angular/dom-adapter.ts

+159-63
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,24 @@
1-
import { ElementSchemaRegistry } from "@angular/compiler";
2-
import { SchemaMetadata } from "@angular/core";
3-
import { Parse5DomAdapter } from "./parse5_adapter";
4-
import { setRootDomAdapter } from "./private_import_platform-browser";
1+
/* tslint:disable */
2+
import { Type } from "@angular/core";
3+
import { DomAdapter } from "./private_import_platform-browser";
54
import { rendererLog } from "./trace";
65
import { print } from "./lang-facade";
76

8-
export enum SecurityContext {
9-
NONE,
10-
HTML,
11-
STYLE,
12-
SCRIPT,
13-
URL,
14-
RESOURCE_URL,
15-
}
16-
17-
export class NativeScriptElementSchemaRegistry extends ElementSchemaRegistry {
18-
hasProperty(_tagName: string, _propName: string): boolean {
19-
return true;
20-
}
21-
22-
hasElement(_tagName: string, _schemaMetas: SchemaMetadata[]): boolean {
23-
return true;
24-
}
25-
26-
27-
getMappedPropName(propName: string): string {
28-
return propName;
29-
}
30-
31-
getDefaultComponentElementName(): string {
32-
return "ng-component";
33-
}
34-
35-
securityContext(_tagName: string, _propName: string): any {
36-
return SecurityContext.NONE;
37-
}
38-
39-
validateProperty(_name: string): { error: boolean, msg?: string } {
40-
return { error: false };
41-
}
42-
43-
validateAttribute(_name: string): { error: boolean, msg?: string } {
44-
return { error: false };
45-
}
46-
47-
allKnownElementNames(): string[] {
48-
return [];
49-
}
50-
51-
normalizeAnimationStyleProperty(propName: string): string {
52-
return propName;
53-
}
7+
export class NativeScriptDomAdapter implements DomAdapter {
8+
static makeCurrent() {
549

55-
normalizeAnimationStyleValue(
56-
_camelCaseProp: string,
57-
_userProvidedProp: string,
58-
val: string | number
59-
):
60-
{ error: string, value: string } {
61-
return { error: null, value: val.toString() };
62-
}
63-
}
10+
// Don't register when bundling (likely AoT setup).
11+
if (!global.TNS_WEBPACK) {
12+
try {
13+
const privateAPI = global.require("@angular/platform-browser").__platform_browser_private__;
14+
const setRootDomAdapter = privateAPI.setRootDomAdapter;
6415

65-
export class NativeScriptDomAdapter extends Parse5DomAdapter {
66-
static makeCurrent() {
67-
rendererLog("Setting DOM");
68-
setRootDomAdapter(new NativeScriptDomAdapter());
16+
rendererLog("Setting root DOM adapter...");
17+
setRootDomAdapter(new NativeScriptDomAdapter());
18+
} catch (e) {
19+
rendererLog("@angular/platform-browser package not present. NOT setting root DOM adapter...");
20+
}
21+
}
6922
}
7023

7124
hasProperty(_element: any, _name: string) {
@@ -87,4 +40,147 @@ export class NativeScriptDomAdapter extends Parse5DomAdapter {
8740

8841
logGroupEnd(): void {
8942
}
43+
44+
get attrToPropMap(): {[key: string]: string} { throw new Error("Not implemented!"); };
45+
set attrToPropMap(_value: {[key: string]: string}) { throw new Error("Not implemented!"); };
46+
47+
public resourceLoaderType: Type<any> = null;
48+
setProperty(_el: Element, _name: string, _value: any): any /** TODO #9100 */ { throw new Error("Not implemented!") }
49+
getProperty(_el: Element, _name: string): any { throw new Error("Not implemented!") }
50+
invoke(_el: Element, _methodName: string, _args: any[]): any { throw new Error("Not implemented!") }
51+
52+
parse(_templateHtml: string): any /** TODO #9100 */ { throw new Error("Not implemented!") }
53+
query(_selector: string): any { throw new Error("Not implemented!") }
54+
querySelector(_el: any /** TODO #9100 */, _selector: string): HTMLElement { throw new Error("Not implemented!") }
55+
querySelectorAll(_el: any /** TODO #9100 */, _selector: string): any[] { throw new Error("Not implemented!") }
56+
on(
57+
_el: any /** TODO #9100 */, _evt: any /** TODO #9100 */, _listener: any /** TODO #9100 */): any
58+
/** TODO #9100 */ { throw new Error("Not implemented!") }
59+
onAndCancel(
60+
_el: any /** TODO #9100 */, _evt: any /** TODO #9100 */,
61+
_listener: any /** TODO #9100 */): Function { throw new Error("Not implemented!") }
62+
dispatchEvent(_el: any /** TODO #9100 */, _evt: any /** TODO #9100 */): any
63+
/** TODO #9100 */ { throw new Error("Not implemented!") }
64+
createMouseEvent(_eventType: any /** TODO #9100 */): any { throw new Error("Not implemented!") }
65+
createEvent(_eventType: string): any { throw new Error("Not implemented!") }
66+
preventDefault(_evt: any /** TODO #9100 */): any /** TODO #9100 */ { throw new Error("Not implemented!") }
67+
isPrevented(_evt: any /** TODO #9100 */): boolean { throw new Error("Not implemented!") }
68+
getInnerHTML(_el: any /** TODO #9100 */): string { throw new Error("Not implemented!") }
69+
70+
getTemplateContent(_el: any /** TODO #9100 */): any { throw new Error("Not implemented!") }
71+
getOuterHTML(_el: any /** TODO #9100 */): string { throw new Error("Not implemented!") }
72+
nodeName(_node: any /** TODO #9100 */): string { throw new Error("Not implemented!") }
73+
nodeValue(_node: any /** TODO #9100 */): string { throw new Error("Not implemented!") }
74+
type(_node: any /** TODO #9100 */): string { throw new Error("Not implemented!") }
75+
content(_node: any /** TODO #9100 */): any { throw new Error("Not implemented!") }
76+
firstChild(_el: any /** TODO #9100 */): Node { throw new Error("Not implemented!") }
77+
nextSibling(_el: any /** TODO #9100 */): Node { throw new Error("Not implemented!") }
78+
parentElement(_el: any /** TODO #9100 */): Node { throw new Error("Not implemented!") }
79+
childNodes(_el: any /** TODO #9100 */): Node[] { throw new Error("Not implemented!") }
80+
childNodesAsList(_el: any /** TODO #9100 */): Node[] { throw new Error("Not implemented!") }
81+
clearNodes(_el: any /** TODO #9100 */): any /** TODO #9100 */ { throw new Error("Not implemented!") }
82+
appendChild(_el: any /** TODO #9100 */, _node: any /** TODO #9100 */): any
83+
/** TODO #9100 */ { throw new Error("Not implemented!") }
84+
removeChild(_el: any /** TODO #9100 */, _node: any /** TODO #9100 */): any
85+
/** TODO #9100 */ { throw new Error("Not implemented!") }
86+
replaceChild(
87+
_el: any /** TODO #9100 */, _newNode: any /** TODO #9100 */,
88+
_oldNode: any /** TODO #9100 */): any /** TODO #9100 */ { throw new Error("Not implemented!") }
89+
remove(_el: any /** TODO #9100 */): Node { throw new Error("Not implemented!") }
90+
insertBefore(_el: any /** TODO #9100 */, _node: any /** TODO #9100 */): any
91+
/** TODO #9100 */ { throw new Error("Not implemented!") }
92+
insertAllBefore(_el: any /** TODO #9100 */, _nodes: any /** TODO #9100 */): any
93+
/** TODO #9100 */ { throw new Error("Not implemented!") }
94+
insertAfter(_el: any /** TODO #9100 */, _node: any /** TODO #9100 */): any
95+
/** TODO #9100 */ { throw new Error("Not implemented!") }
96+
setInnerHTML(_el: any /** TODO #9100 */, _value: any /** TODO #9100 */): any
97+
/** TODO #9100 */ { throw new Error("Not implemented!") }
98+
getText(_el: any /** TODO #9100 */): string { throw new Error("Not implemented!") }
99+
setText(_el: any /** TODO #9100 */, _value: string): any /** TODO #9100 */ { throw new Error("Not implemented!") }
100+
getValue(_el: any /** TODO #9100 */): string { throw new Error("Not implemented!") }
101+
setValue(_el: any /** TODO #9100 */, _value: string): any /** TODO #9100 */ { throw new Error("Not implemented!") }
102+
getChecked(_el: any /** TODO #9100 */): boolean { throw new Error("Not implemented!") }
103+
setChecked(_el: any /** TODO #9100 */, _value: boolean): any /** TODO #9100 */ { throw new Error("Not implemented!") }
104+
createComment(_text: string): any { throw new Error("Not implemented!") }
105+
createTemplate(_html: any /** TODO #9100 */): HTMLElement { throw new Error("Not implemented!") }
106+
createElement(_tagName: any /** TODO #9100 */, _doc?: any /** TODO #9100 */): HTMLElement { throw new Error("Not implemented!") }
107+
createElementNS(_ns: string, _tagName: string, _doc?: any /** TODO #9100 */): Element { throw new Error("Not implemented!") }
108+
createTextNode(_text: string, _doc?: any /** TODO #9100 */): Text { throw new Error("Not implemented!") }
109+
createScriptTag(_attrName: string, _attrValue: string, _doc?: any /** TODO #9100 */):
110+
HTMLElement { throw new Error("Not implemented!") }
111+
createStyleElement(_css: string, _doc?: any /** TODO #9100 */): HTMLStyleElement { throw new Error("Not implemented!") }
112+
createShadowRoot(_el: any /** TODO #9100 */): any { throw new Error("Not implemented!") }
113+
getShadowRoot(_el: any /** TODO #9100 */): any { throw new Error("Not implemented!") }
114+
getHost(_el: any /** TODO #9100 */): any { throw new Error("Not implemented!") }
115+
getDistributedNodes(_el: any /** TODO #9100 */): Node[] { throw new Error("Not implemented!") }
116+
clone /*<T extends Node>*/ (_node: Node /*T*/): Node /*T*/ { throw new Error("Not implemented!") }
117+
getElementsByClassName(_element: any /** TODO #9100 */, _name: string): HTMLElement[] { throw new Error("Not implemented!") }
118+
getElementsByTagName(_element: any /** TODO #9100 */, _name: string): HTMLElement[] { throw new Error("Not implemented!") }
119+
classList(_element: any /** TODO #9100 */): any[] { throw new Error("Not implemented!") }
120+
addClass(_element: any /** TODO #9100 */, _className: string): any /** TODO #9100 */ { throw new Error("Not implemented!") }
121+
removeClass(_element: any /** TODO #9100 */, _className: string): any /** TODO #9100 */ { throw new Error("Not implemented!") }
122+
hasClass(_element: any /** TODO #9100 */, _className: string): boolean { throw new Error("Not implemented!") }
123+
setStyle(_element: any /** TODO #9100 */, _styleName: string, _styleValue: string): any
124+
/** TODO #9100 */ { throw new Error("Not implemented!") }
125+
removeStyle(_element: any /** TODO #9100 */, _styleName: string): any /** TODO #9100 */ { throw new Error("Not implemented!") }
126+
getStyle(_element: any /** TODO #9100 */, _styleName: string): string { throw new Error("Not implemented!") }
127+
hasStyle(_element: any /** TODO #9100 */, _styleName: string, _styleValue?: string):
128+
boolean { throw new Error("Not implemented!") }
129+
tagName(_element: any /** TODO #9100 */): string { throw new Error("Not implemented!") }
130+
attributeMap(_element: any /** TODO #9100 */): Map<string, string> { throw new Error("Not implemented!") }
131+
hasAttribute(_element: any /** TODO #9100 */, _attribute: string): boolean { throw new Error("Not implemented!") }
132+
hasAttributeNS(_element: any /** TODO #9100 */, _ns: string, _attribute: string): boolean { throw new Error("Not implemented!") }
133+
getAttribute(_element: any /** TODO #9100 */, _attribute: string): string { throw new Error("Not implemented!") }
134+
getAttributeNS(_element: any /** TODO #9100 */, _ns: string, _attribute: string): string { throw new Error("Not implemented!") }
135+
setAttribute(_element: any /** TODO #9100 */, _name: string, _value: string): any
136+
/** TODO #9100 */ { throw new Error("Not implemented!") }
137+
setAttributeNS(_element: any /** TODO #9100 */, _ns: string, _name: string, _value: string):
138+
any /** TODO #9100 */ { throw new Error("Not implemented!") }
139+
removeAttribute(_element: any /** TODO #9100 */, _attribute: string): any
140+
/** TODO #9100 */ { throw new Error("Not implemented!") }
141+
removeAttributeNS(_element: any /** TODO #9100 */, _ns: string, _attribute: string): any
142+
/** TODO #9100 */ { throw new Error("Not implemented!") }
143+
templateAwareRoot(_el: any /** TODO #9100 */): any /** TODO #9100 */ { throw new Error("Not implemented!") }
144+
createHtmlDocument(): HTMLDocument { throw new Error("Not implemented!") }
145+
defaultDoc(): HTMLDocument { throw new Error("Not implemented!") }
146+
getBoundingClientRect(_el: any /** TODO #9100 */): any /** TODO #9100 */ { throw new Error("Not implemented!") }
147+
getTitle(): string { throw new Error("Not implemented!") }
148+
setTitle(_newTitle: string): any /** TODO #9100 */ { throw new Error("Not implemented!") }
149+
elementMatches(_n: any /** TODO #9100 */, _selector: string): boolean { throw new Error("Not implemented!") }
150+
isTemplateElement(_el: any): boolean { throw new Error("Not implemented!") }
151+
isTextNode(_node: any /** TODO #9100 */): boolean { throw new Error("Not implemented!") }
152+
isCommentNode(_node: any /** TODO #9100 */): boolean { throw new Error("Not implemented!") }
153+
isElementNode(_node: any /** TODO #9100 */): boolean { throw new Error("Not implemented!") }
154+
hasShadowRoot(_node: any /** TODO #9100 */): boolean { throw new Error("Not implemented!") }
155+
isShadowRoot(_node: any /** TODO #9100 */): boolean { throw new Error("Not implemented!") }
156+
importIntoDoc /*<T extends Node>*/ (_node: Node /*T*/): Node /*T*/ { throw new Error("Not implemented!") }
157+
adoptNode /*<T extends Node>*/ (_node: Node /*T*/): Node /*T*/ { throw new Error("Not implemented!") }
158+
getHref(_element: any /** TODO #9100 */): string { throw new Error("Not implemented!") }
159+
getEventKey(_event: any /** TODO #9100 */): string { throw new Error("Not implemented!") }
160+
resolveAndSetHref(_element: any /** TODO #9100 */, _baseUrl: string, _href: string): any
161+
/** TODO #9100 */ { throw new Error("Not implemented!") }
162+
supportsDOMEvents(): boolean { throw new Error("Not implemented!") }
163+
supportsNativeShadowDOM(): boolean { throw new Error("Not implemented!") }
164+
getGlobalEventTarget(_target: string): any { throw new Error("Not implemented!") }
165+
getHistory(): History { throw new Error("Not implemented!") }
166+
getLocation(): Location { throw new Error("Not implemented!") }
167+
getBaseHref(): string { throw new Error("Not implemented!") }
168+
resetBaseElement(): void { throw new Error("Not implemented!") }
169+
getUserAgent(): string { throw new Error("Not implemented!") }
170+
setData(_element: any /** TODO #9100 */, _name: string, _value: string): any
171+
/** TODO #9100 */ { throw new Error("Not implemented!") }
172+
getComputedStyle(_element: any /** TODO #9100 */): any { throw new Error("Not implemented!") }
173+
getData(_element: any /** TODO #9100 */, _name: string): string { throw new Error("Not implemented!") }
174+
setGlobalVar(_name: string, _value: any): any /** TODO #9100 */ { throw new Error("Not implemented!") }
175+
supportsWebAnimation(): boolean { throw new Error("Not implemented!") }
176+
performanceNow(): number { throw new Error("Not implemented!") }
177+
getAnimationPrefix(): string { throw new Error("Not implemented!") }
178+
getTransitionEnd(): string { throw new Error("Not implemented!") }
179+
supportsAnimation(): boolean { throw new Error("Not implemented!") }
180+
181+
supportsCookies(): boolean { throw new Error("Not implemented!") }
182+
getCookie(_name: string): string { throw new Error("Not implemented!") }
183+
setCookie(_name: string, _value: string): any /** TODO #9100 */ { throw new Error("Not implemented!") }
90184
}
185+
186+
NativeScriptDomAdapter.makeCurrent();

Diff for: nativescript-angular/package.json

-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@
3030
"@angular/compiler": "~2.4.3",
3131
"@angular/http": "~2.4.3",
3232
"@angular/platform-browser": "~2.4.3",
33-
"@angular/platform-browser-dynamic": "~2.4.3",
3433
"@angular/forms": "~2.4.3",
3534
"@angular/router": "~3.4.3",
3635
"rxjs": "~5.0.1",
3736
"reflect-metadata": "~0.1.8",
38-
"parse5": "1.3.2",
3937
"punycode": "1.3.2",
4038
"querystring": "0.2.0",
4139
"url": "0.10.3"

0 commit comments

Comments
 (0)