Skip to content

Commit 0e4924f

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 0e4924f

File tree

5 files changed

+221
-831
lines changed

5 files changed

+221
-831
lines changed

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

+158-63
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,23 @@
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+
import { Type } from "@angular/core";
2+
import { DomAdapter } from "./private_import_platform-browser";
53
import { rendererLog } from "./trace";
64
import { print } from "./lang-facade";
75

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-
}
6+
export class NativeScriptDomAdapter implements DomAdapter {
7+
static makeCurrent() {
548

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-
}
9+
// Don't register when bundling (likely AoT setup).
10+
if (!global.TNS_WEBPACK) {
11+
try {
12+
const privateAPI = global.require("@angular/platform-browser").__platform_browser_private__;
13+
const setRootDomAdapter = privateAPI.setRootDomAdapter;
6414

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

7123
hasProperty(_element: any, _name: string) {
@@ -87,4 +39,147 @@ export class NativeScriptDomAdapter extends Parse5DomAdapter {
8739

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