From f41b60789956270c2cc744db67a04d95cf32ca15 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Sun, 12 Jul 2020 20:57:23 -0700 Subject: [PATCH] chore: cleanup --- .gitignore | 4 + .../styling/root-views-css-classes-tests.ts | 4 +- packages/core/__tests__/unit/tsconfig.json | 5 +- .../__tests__/unit/xml/test-angular-xml.ts | 6 +- ...ns-core-modules.d.ts => global-types.d.ts} | 137 ++++- packages/core/index.d.ts | 5 +- packages/core/index.ts | 9 +- packages/core/module.d.ts | 132 ----- packages/core/references.d.ts | 2 +- packages/core/ui/frame/activity.android.ts | 4 +- packages/core/xml/index.js | 553 ++++++++++++++++++ packages/core/xml/index.ts | 2 +- 12 files changed, 709 insertions(+), 154 deletions(-) rename packages/core/{tns-core-modules.d.ts => global-types.d.ts} (54%) delete mode 100644 packages/core/module.d.ts create mode 100644 packages/core/xml/index.js diff --git a/.gitignore b/.gitignore index c9faf8cc0..3275cbbdd 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,7 @@ testem.log # System Files .DS_Store Thumbs.db + +# core +# https://github.com/NativeScript/nativescript-dev-webpack/issues/932 +!packages/core/xml/index.js \ No newline at end of file diff --git a/packages/core/__tests__/e2e/automated/app/ui/styling/root-views-css-classes-tests.ts b/packages/core/__tests__/e2e/automated/app/ui/styling/root-views-css-classes-tests.ts index a2ccaeefe..7ccd208ee 100644 --- a/packages/core/__tests__/e2e/automated/app/ui/styling/root-views-css-classes-tests.ts +++ b/packages/core/__tests__/e2e/automated/app/ui/styling/root-views-css-classes-tests.ts @@ -95,7 +95,7 @@ function _test_orientation_css_class(rootView: View, shouldSetClassName: boolean appOrientation = Application.android.orientation; } else { - appOrientation = Utils.ios.orientation; + appOrientation = Application.ios.orientation; } if (appOrientation === "portrait") { TKUnit.assertTrue(cssClasses.has(PORTRAIT_ORIENTATION_CSS_CLASS), `${PORTRAIT_ORIENTATION_CSS_CLASS} CSS class is missing`); @@ -129,7 +129,7 @@ function _test_system_appearance_css_class(rootView: View, shouldSetClassName: b systemAppearance = Application.android.systemAppearance; } else { - systemAppearance = Utils.ios.systemAppearance; + systemAppearance = Application.ios.systemAppearance; } if (isIOS && Utils.ios.MajorVersion <= 12) { TKUnit.assertFalse(cssClasses.has(DARK_SYSTEM_APPEARANCE_CSS_CLASS), `${DARK_SYSTEM_APPEARANCE_CSS_CLASS} CSS class is present`); diff --git a/packages/core/__tests__/unit/tsconfig.json b/packages/core/__tests__/unit/tsconfig.json index f670b254c..b099dca5a 100644 --- a/packages/core/__tests__/unit/tsconfig.json +++ b/packages/core/__tests__/unit/tsconfig.json @@ -21,9 +21,12 @@ ], "baseUrl": ".", "paths": { + "@nativescript/core": [ + "../../index.ts" + ], "@nativescript/core/*": [ "../../*" - ] + ], } }, "include": [ diff --git a/packages/core/__tests__/unit/xml/test-angular-xml.ts b/packages/core/__tests__/unit/xml/test-angular-xml.ts index 189666b6f..223d44904 100644 --- a/packages/core/__tests__/unit/xml/test-angular-xml.ts +++ b/packages/core/__tests__/unit/xml/test-angular-xml.ts @@ -1,5 +1,5 @@ import { assert } from 'chai'; -const xml = require('@nativescript/core/xml'); +import { XmlParser, ParserEventType } from '@nativescript/core/xml'; describe('angular xml parser', () => { let last_element = null; @@ -7,9 +7,9 @@ describe('angular xml parser', () => { let parser = null; beforeEach(() => { - parser = new xml.XmlParser(function (event) { + parser = new XmlParser(function (event) { switch (event.eventType) { - case xml.ParserEventType.StartElement: + case ParserEventType.StartElement: last_element = event.elementName; last_attrs = event.attributes; break; diff --git a/packages/core/tns-core-modules.d.ts b/packages/core/global-types.d.ts similarity index 54% rename from packages/core/tns-core-modules.d.ts rename to packages/core/global-types.d.ts index dce2f547c..409e53e30 100644 --- a/packages/core/tns-core-modules.d.ts +++ b/packages/core/global-types.d.ts @@ -1,3 +1,136 @@ +declare var global: NodeJS.Global & typeof globalThis; + +interface ModuleResolver { + /** + * A function used to resolve the exports for a module. + * @param uri The name of the module to be resolved. + */ + (uri: string): any; +} + +/** + * An extended JavaScript Error which will have the nativeError property initialized in case the error is caused by executing platform-specific code. + */ +declare interface NativeScriptError extends Error { + /** + * Represents the native error object. + */ + nativeError: any; +} + +//Augment the NodeJS global type with our own extensions +declare namespace NodeJS { + interface Global { + android?: any; + require(id: string): any; + + moduleMerge(sourceExports: any, destExports: any): void; + + registerModule(name: string, loader: (name: string) => any): void; + /** + * Register all modules from a webpack context. + * The context is one created using the following webpack utility: + * https://webpack.js.org/guides/dependency-management/#requirecontext + * + * The extension map is optional, modules in the webpack context will have their original file extension (e.g. may be ".ts" or ".scss" etc.), + * while the built-in module builders in {N} will look for ".js", ".css" or ".xml" files. Adding a map such as: + * ``` + * { ".ts": ".js" } + * ``` + * Will resolve lookups for .js to the .ts file. + * By default scss and ts files are mapped. + */ + registerWebpackModules(context: { keys(): string[]; (key: string): any }, extensionMap?: { [originalFileExtension: string]: string }); + + /** + * The NativeScript XML builder, style-scope, application modules use various resources such as: + * app.css, page.xml files and modules during the application life-cycle. + * The moduleResolvers can be used to provide additional mechanisms to locate such resources. + * For example: + * ``` + * global.moduleResolvers.unshift(uri => uri === "main-page" ? require("main-page") : null); + * ``` + * More advanced scenarios will allow for specific bundlers to integrate their module resolving mechanisms. + * When adding resolvers at the start of the array, avoid throwing and return null instead so subsequent resolvers may try to resolve the resource. + * By default the only member of the array is global.require, as last resort - if it fails to find a module it will throw. + */ + readonly moduleResolvers: ModuleResolver[]; + + /** + * + * @param name Name of the module to be loaded + * @param loadForUI Is this UI module is being loaded for UI from @nativescript/core/ui/builder. + * Xml, css/scss and js/ts modules for pages and custom-components should load with loadForUI=true. + * Passing "true" will enable the HMR mechanics this module. Default value is false. + */ + loadModule(name: string, loadForUI?: boolean): any; + + /** + * Checks if the module has been registered with `registerModule` or in `registerWebpackModules` + * @param name Name of the module + */ + moduleExists(name: string): boolean; + + getRegisteredModules(): string[]; + + _unregisterModule(name: string): void; + + _isModuleLoadedForUI(moduleName: string): boolean; + + onGlobalLayoutListener: any; + zonedCallback(callback: Function): Function; + Reflect?: any; + Deprecated(target: Object, key?: string | symbol, descriptor?: any): any; + Experimental(target: Object, key?: string | symbol, descriptor?: any): any; + + __native?: any; + __inspector?: any; + __extends: any; + __onLiveSync: (context?: { type: string; path: string }) => void; + __onLiveSyncCore: (context?: { type: string; path: string }) => void; + __onUncaughtError: (error: NativeScriptError) => void; + __onDiscardedError: (error: NativeScriptError) => void; + TNS_WEBPACK?: boolean; + __snapshot?: boolean; + __requireOverride?: (name: string, dir: string) => any; + } +} + +declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): number; +declare function clearTimeout(timeoutId: number): void; +declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): number; +declare function clearInterval(intervalId: number): void; + +declare type ModuleType = 'markup' | 'script' | 'style'; + +/** + * Define a module context for Hot Module Replacement. + */ +interface ModuleContext { + /** + * The type of the module for replacement. + */ + type: ModuleType; + + /** + * The path of the module for replacement. + */ + path: string; +} + +// Define a minimal subset of NodeRequire and NodeModule so user apps can compile without +// installing @types/node + +interface NodeRequire { + (id: string): any; +} + +interface NodeModule { + exports: any; + id: string; + filename: string; +} + declare enum RequestContext { 'audio', 'beacon', @@ -180,7 +313,3 @@ declare class WeakRef { get(): T; clear(): void; } - -//Dialogs -// declare function alert(message?: any): void; -// declare function confirm(message?: string): boolean; diff --git a/packages/core/index.d.ts b/packages/core/index.d.ts index c06cf50d5..842f870c2 100644 --- a/packages/core/index.d.ts +++ b/packages/core/index.d.ts @@ -1,5 +1,4 @@ -/// -/// +/// export { ApplicationEventData, LaunchEventData, OrientationChangedEventData, UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData, iOSApplication, AndroidApplication, AndroidActivityEventData, AndroidActivityBundleEventData, AndroidActivityRequestPermissionsEventData, AndroidActivityResultEventData, AndroidActivityNewIntentEventData, AndroidActivityBackPressedEventData } from './application'; import { getMainEntry, getRootView, _resetRootView, getResources, setResources, setCssFileName, getCssFileName, loadAppCss, addCss, on, off, run, orientation, getNativeApplication, hasLaunched, AndroidApplication, iOSApplication } from './application'; export declare const Application: { @@ -75,7 +74,7 @@ export { encoding } from './text'; export * from './trace'; export * from './ui'; -import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, ios as iosUtils, Source } from './utils'; +import { GC, isFontIconURI, isDataURI, isFileOrResourcePath, executeOnMainThread, mainThreadify, isMainThread, dispatchToMainThread, releaseNativeObject, getModuleName, openFile, openUrl, isRealDevice, layout, ad as androidUtils, iOSNativeHelper as iosUtils, Source } from './utils'; import { ClassInfo, getClass, getBaseClasses, getClassInfo, isBoolean, isDefined, isFunction, isNullOrUndefined, isNumber, isObject, isString, isUndefined, toUIString, verifyCallback } from './utils/types'; export declare const Utils: { GC: typeof GC; diff --git a/packages/core/index.ts b/packages/core/index.ts index a53fac4b3..f0d64e7a5 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -1,5 +1,4 @@ -/// -/// +/// // Init globals first import { initGlobal } from './globals'; @@ -9,7 +8,7 @@ initGlobal(); export { ApplicationEventData, LaunchEventData, OrientationChangedEventData, UnhandledErrorEventData, DiscardedErrorEventData, CssChangedEventData, LoadAppCSSEventData, iOSApplication, AndroidApplication, AndroidActivityEventData, AndroidActivityBundleEventData, AndroidActivityRequestPermissionsEventData, AndroidActivityResultEventData, AndroidActivityNewIntentEventData, AndroidActivityBackPressedEventData } from './application'; // Export all methods and fields from "application" as Application -import { launchEvent, displayedEvent, uncaughtErrorEvent, discardedErrorEvent, suspendEvent, resumeEvent, exitEvent, lowMemoryEvent, orientationChangedEvent, getMainEntry, getRootView, _resetRootView, getResources, setResources, setCssFileName, getCssFileName, loadAppCss, addCss, on, off, run, orientation, getNativeApplication, hasLaunched, android, ios } from './application'; +import { launchEvent, displayedEvent, uncaughtErrorEvent, discardedErrorEvent, suspendEvent, resumeEvent, exitEvent, lowMemoryEvent, orientationChangedEvent, getMainEntry, getRootView, _resetRootView, getResources, setResources, setCssFileName, getCssFileName, loadAppCss, addCss, on, off, run, orientation, getNativeApplication, hasLaunched, android as appAndroid, ios as iosApp } from './application'; export const Application = { launchEvent, displayedEvent, @@ -37,8 +36,8 @@ export const Application = { getNativeApplication, hasLaunched, - android: android, - ios: ios, + android: appAndroid, + ios: iosApp, }; // Export all methods from "application-settings" as ApplicationSettings diff --git a/packages/core/module.d.ts b/packages/core/module.d.ts deleted file mode 100644 index 9e2b5b652..000000000 --- a/packages/core/module.d.ts +++ /dev/null @@ -1,132 +0,0 @@ -declare var global: NodeJS.Global & typeof globalThis; - -interface ModuleResolver { - /** - * A function used to resolve the exports for a module. - * @param uri The name of the module to be resolved. - */ - (uri: string): any; -} - -/** - * An extended JavaScript Error which will have the nativeError property initialized in case the error is caused by executing platform-specific code. - */ -declare interface NativeScriptError extends Error { - /** - * Represents the native error object. - */ - nativeError: any; -} - -//Augment the NodeJS global type with our own extensions -declare namespace NodeJS { - interface Global { - android?: any; - require(id: string): any; - - moduleMerge(sourceExports: any, destExports: any): void; - - registerModule(name: string, loader: (name: string) => any): void; - /** - * Register all modules from a webpack context. - * The context is one created using the following webpack utility: - * https://webpack.js.org/guides/dependency-management/#requirecontext - * - * The extension map is optional, modules in the webpack context will have their original file extension (e.g. may be ".ts" or ".scss" etc.), - * while the built-in module builders in {N} will look for ".js", ".css" or ".xml" files. Adding a map such as: - * ``` - * { ".ts": ".js" } - * ``` - * Will resolve lookups for .js to the .ts file. - * By default scss and ts files are mapped. - */ - registerWebpackModules(context: { keys(): string[]; (key: string): any }, extensionMap?: { [originalFileExtension: string]: string }); - - /** - * The NativeScript XML builder, style-scope, application modules use various resources such as: - * app.css, page.xml files and modules during the application life-cycle. - * The moduleResolvers can be used to provide additional mechanisms to locate such resources. - * For example: - * ``` - * global.moduleResolvers.unshift(uri => uri === "main-page" ? require("main-page") : null); - * ``` - * More advanced scenarios will allow for specific bundlers to integrate their module resolving mechanisms. - * When adding resolvers at the start of the array, avoid throwing and return null instead so subsequent resolvers may try to resolve the resource. - * By default the only member of the array is global.require, as last resort - if it fails to find a module it will throw. - */ - readonly moduleResolvers: ModuleResolver[]; - - /** - * - * @param name Name of the module to be loaded - * @param loadForUI Is this UI module is being loaded for UI from @nativescript/core/ui/builder. - * Xml, css/scss and js/ts modules for pages and custom-components should load with loadForUI=true. - * Passing "true" will enable the HMR mechanics this module. Default value is false. - */ - loadModule(name: string, loadForUI?: boolean): any; - - /** - * Checks if the module has been registered with `registerModule` or in `registerWebpackModules` - * @param name Name of the module - */ - moduleExists(name: string): boolean; - - getRegisteredModules(): string[]; - - _unregisterModule(name: string): void; - - _isModuleLoadedForUI(moduleName: string): boolean; - - onGlobalLayoutListener: any; - zonedCallback(callback: Function): Function; - Reflect?: any; - Deprecated(target: Object, key?: string | symbol, descriptor?: any): any; - Experimental(target: Object, key?: string | symbol, descriptor?: any): any; - - __native?: any; - __inspector?: any; - __extends: any; - __onLiveSync: (context?: { type: string; path: string }) => void; - __onLiveSyncCore: (context?: { type: string; path: string }) => void; - __onUncaughtError: (error: NativeScriptError) => void; - __onDiscardedError: (error: NativeScriptError) => void; - TNS_WEBPACK?: boolean; - __snapshot?: boolean; - __requireOverride?: (name: string, dir: string) => any; - } -} - -declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): number; -declare function clearTimeout(timeoutId: number): void; -declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): number; -declare function clearInterval(intervalId: number): void; - -declare type ModuleType = 'markup' | 'script' | 'style'; - -/** - * Define a module context for Hot Module Replacement. - */ -interface ModuleContext { - /** - * The type of the module for replacement. - */ - type: ModuleType; - - /** - * The path of the module for replacement. - */ - path: string; -} - -// Define a minimal subset of NodeRequire and NodeModule so user apps can compile without -// installing @types/node - -interface NodeRequire { - (id: string): any; -} - -interface NodeModule { - exports: any; - id: string; - filename: string; -} diff --git a/packages/core/references.d.ts b/packages/core/references.d.ts index 6117f2a9d..70be1dec6 100644 --- a/packages/core/references.d.ts +++ b/packages/core/references.d.ts @@ -1,4 +1,4 @@ /// /// /// -/// +/// diff --git a/packages/core/ui/frame/activity.android.ts b/packages/core/ui/frame/activity.android.ts index 64afd6465..7fd612039 100644 --- a/packages/core/ui/frame/activity.android.ts +++ b/packages/core/ui/frame/activity.android.ts @@ -1,9 +1,9 @@ import { setActivityCallbacks, AndroidActivityCallbacks } from '.'; -import * as globals from '../../globals'; +import { initGlobal } from '../../globals'; import * as appModule from '../../application'; if (global.__snapshot) { - globals.initGlobal(); + initGlobal(); } //@ts-ignore diff --git a/packages/core/xml/index.js b/packages/core/xml/index.js new file mode 100644 index 000000000..acf9f8162 --- /dev/null +++ b/packages/core/xml/index.js @@ -0,0 +1,553 @@ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.XmlParser = exports.ParserEvent = exports.ParserEventType = void 0; +var easysax = require("../js-libs/easysax"); +var ParserEventType = (function () { + function ParserEventType() { + } + ParserEventType.StartElement = 'StartElement'; + ParserEventType.EndElement = 'EndElement'; + ParserEventType.Text = 'Text'; + ParserEventType.CDATA = 'CDATA'; + ParserEventType.Comment = 'Comment'; + return ParserEventType; +}()); +exports.ParserEventType = ParserEventType; +var ParserEvent = (function () { + function ParserEvent(eventType, position, prefix, namespace, elementName, attributes, data) { + this._eventType = eventType; + this._position = position; + this._prefix = prefix; + this._namespace = namespace; + this._elementName = elementName; + this._attributes = attributes; + this._data = data; + } + ParserEvent.prototype.toString = function () { + return JSON.stringify({ + eventType: this.eventType, + position: this.position, + prefix: this.prefix, + namespace: this.namespace, + elementName: this.elementName, + attributes: this.attributes, + data: this.data, + }); + }; + Object.defineProperty(ParserEvent.prototype, "eventType", { + get: function () { + return this._eventType; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(ParserEvent.prototype, "position", { + get: function () { + return this._position; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(ParserEvent.prototype, "prefix", { + get: function () { + return this._prefix; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(ParserEvent.prototype, "namespace", { + get: function () { + return this._namespace; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(ParserEvent.prototype, "elementName", { + get: function () { + return this._elementName; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(ParserEvent.prototype, "attributes", { + get: function () { + return this._attributes; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(ParserEvent.prototype, "data", { + get: function () { + return this._data; + }, + enumerable: false, + configurable: true + }); + return ParserEvent; +}()); +exports.ParserEvent = ParserEvent; +var _ampCodes; +var _entitySearchRegEx = /&#(\d+);|&#x([0123456789abcdef]+);|&(\w+);/gi; +function _generateAmpMap() { + var objCodes = { + Tab: 9, + NewLine: 10, + excl: 33, + quot: 34, + QUOT: 34, + num: 35, + dollar: 36, + percent: 37, + amp: 38, + AMP: 38, + apos: 39, + lpar: 40, + rpar: 41, + ast: 42, + midast: 42, + plus: 43, + comma: 44, + period: 46, + sol: 47, + colon: 58, + semi: 59, + lt: 60, + LT: 60, + equals: 61, + gt: 62, + GT: 62, + quest: 63, + commat: 64, + lsqb: 91, + lbrack: 91, + bsol: 92, + rsqb: 92, + rbrack: 92, + Hat: 94, + lowbar: 95, + grave: 96, + DiacriticalGrave: 96, + lcub: 123, + lbrace: 123, + verbar: 124, + vert: 124, + VerticalLine: 124, + rcub: 125, + rbrace: 125, + nbsp: 160, + iexcl: 161, + cent: 162, + pound: 163, + curren: 164, + yen: 165, + brvbar: 166, + brkbar: 166, + sect: 167, + uml: 168, + copy: 169, + ordf: 170, + laquo: 171, + not: 172, + shy: 173, + reg: 174, + macr: 175, + hibar: 175, + deg: 176, + plusmn: 177, + sup2: 178, + sup3: 179, + acute: 180, + micro: 181, + para: 182, + middot: 183, + cedil: 184, + sup1: 185, + ordm: 186, + raquo: 187, + frac14: 188, + frac12: 189, + frac34: 190, + iquest: 191, + Agrave: 192, + Aacute: 193, + Acirc: 194, + Atilde: 195, + Auml: 196, + Aring: 197, + AElig: 198, + Ccedil: 199, + Egrave: 200, + Eacute: 201, + Ecirc: 202, + Euml: 203, + Igrave: 204, + Iacute: 205, + Icirc: 206, + Iuml: 207, + ETH: 208, + Dstrok: 208, + Ntilde: 209, + Ograve: 210, + Oacute: 211, + Ocirc: 212, + Otilde: 213, + Ouml: 214, + times: 215, + Oslash: 216, + Ugrave: 217, + Uacute: 218, + Ucirc: 219, + Uuml: 220, + Yacute: 221, + THORN: 222, + szlig: 223, + agrave: 224, + aacute: 225, + acirc: 226, + atilde: 227, + auml: 228, + aring: 229, + aelig: 230, + ccedil: 231, + egrave: 232, + eacute: 233, + ecirc: 234, + euml: 235, + igrave: 236, + iacute: 237, + icirc: 238, + iuml: 239, + eth: 240, + ntilde: 241, + ograve: 242, + oacute: 243, + ocirc: 244, + otilde: 245, + ouml: 246, + divide: 247, + oslash: 248, + ugrave: 249, + uacute: 250, + ucirc: 251, + uuml: 252, + yacute: 253, + thorn: 254, + yuml: 255, + fnof: 402, + imped: 437, + gacute: 501, + jmath: 567, + circ: 710, + caron: 711, + Hacek: 711, + breve: 728, + Breve: 728, + dot: 729, + DiacriticalDot: 729, + ring: 730, + ogon: 731, + tilde: 732, + DiacriticalTilde: 732, + dblac: 733, + DiacriticalDoubleAcute: 733, + DownBreve: 785, + UnderBar: 818, + Alpha: 913, + Beta: 914, + Gamma: 915, + Delta: 916, + Epsilon: 917, + Zeta: 918, + Eta: 919, + Theta: 920, + Iota: 921, + Kappa: 922, + Lambda: 923, + Mu: 924, + Nu: 925, + Xi: 926, + Omicron: 927, + Pi: 928, + Rho: 929, + Sigma: 931, + Tau: 932, + Upsilon: 933, + Phi: 934, + Chi: 935, + Psi: 936, + Omega: 937, + alpha: 945, + beta: 946, + gamma: 947, + delta: 948, + epsilon: 949, + epsiv: 949, + varepsilon: 949, + zeta: 950, + eta: 951, + theta: 952, + iota: 953, + kappa: 954, + lambda: 955, + mu: 956, + nu: 957, + xi: 958, + omicron: 959, + pi: 960, + rho: 961, + sigmaf: 962, + sigmav: 962, + varsigma: 962, + sigma: 963, + tau: 964, + upsilon: 965, + phi: 966, + chi: 967, + psi: 968, + omega: 969, + thetav: 977, + vartheta: 977, + thetasym: 977, + Upsi: 978, + upsih: 978, + straightphi: 981, + piv: 982, + varpi: 982, + Gammad: 988, + gammad: 989, + digamma: 989, + kappav: 1008, + varkappa: 1008, + rhov: 1009, + varrho: 1009, + epsi: 1013, + straightepsilon: 1013, + bepsi: 1014, + backepsilon: 1014, + euro: 8364, + trade: 8482, + TRADE: 8482, + forall: 8704, + part: 8706, + larr: 8592, + rarr: 8593, + hyphen: 8208, + dash: 8208, + ndash: 8211, + mdash: 8212, + horbar: 8213, + Vert: 8214, + Verbar: 8214, + lsquo: 8216, + OpenCurlyQuote: 8216, + rsquo: 8217, + rsquor: 8217, + CloseCurlyQuote: 8217, + lsquor: 8218, + sbquo: 8218, + ldquo: 8220, + OpenCurlyDoubleQuote: 8220, + rdquo: 8221, + rdquor: 8221, + CloseCurlyDoubleQuote: 8221, + ldquor: 8222, + bdquo: 8222, + dagger: 8224, + Dagger: 8225, + ddagger: 8225, + bull: 8226, + bullet: 8226, + nldr: 8229, + hellip: 8230, + mldr: 8230, + hybull: 8259, + tdot: 8411, + TripleDot: 8411, + DotDot: 8412, + star: 9734, + phone: 9742, + spades: 9824, + clubs: 9827, + hearts: 9829, + diams: 9830, + female: 9792, + male: 9794, + check: 10003, + checkmark: 10003, + cross: 10007, + VerticalSeparator: 10072, + EmptySmallSquare: 9723, + FilledSmallSquare: 9724, + starf: 9733, + bigstar: 9733, + square: 9633, + squ: 9633, + Square: 9633, + }; + var ampCodes = new Map(); + for (var key in objCodes) { + if (objCodes.hasOwnProperty(key)) { + ampCodes.set(key, objCodes[key]); + } + } + return ampCodes; +} +if (global.__snapshot) { + _ampCodes = _generateAmpMap(); +} +function _HandleAmpEntities(found, decimalValue, hexValue, wordValue) { + if (wordValue) { + if (!_ampCodes) { + _ampCodes = _generateAmpMap(); + } + var res = _ampCodes.get(wordValue); + if (res) { + return String.fromCodePoint(res); + } + return found; + } + if (decimalValue) { + return String.fromCodePoint(parseInt(decimalValue, 10)); + } + return String.fromCodePoint(parseInt(hexValue, 16)); +} +var XmlParser = (function () { + function XmlParser(onEvent, onError, processNamespaces) { + this._processNamespaces = processNamespaces; + this._parser = new easysax.EasySAXParser(); + var that = this; + this._parser.on('startNode', function (elem, attr, uq, tagend, str, pos) { + var attributes = attr(); + if (attributes === true) { + attributes = undefined; + } + if (attributes) { + for (var key in attributes) { + if (attributes.hasOwnProperty(key)) { + attributes[key] = XmlParser._dereferenceEntities(attributes[key]); + } + } + } + var prefix = undefined; + var namespace = undefined; + var name = elem; + if (that._processNamespaces) { + var stackEntry = XmlParser._getNamespacesStackEntry(attributes); + that._namespaceStack.push(stackEntry); + var resolved = that._resolveNamespace(name); + prefix = resolved.prefix; + namespace = resolved.namespace; + name = resolved.name; + } + onEvent(new ParserEvent(ParserEventType.StartElement, pos(), prefix, namespace, name, attributes, undefined)); + }); + this._parser.on('textNode', function (text, uq, pos) { + var data = uq(XmlParser._dereferenceEntities(text)); + onEvent(new ParserEvent(ParserEventType.Text, pos(), undefined, undefined, undefined, undefined, data)); + }); + this._parser.on('endNode', function (elem, uq, tagstart, str, pos) { + var prefix = undefined; + var namespace = undefined; + var name = elem; + if (that._processNamespaces) { + var resolved = that._resolveNamespace(name); + prefix = resolved.prefix; + namespace = resolved.namespace; + name = resolved.name; + } + onEvent(new ParserEvent(ParserEventType.EndElement, pos(), prefix, namespace, name, undefined, undefined)); + if (that._processNamespaces) { + that._namespaceStack.pop(); + } + }); + this._parser.on('cdata', function (data, res, pos) { + onEvent(new ParserEvent(ParserEventType.CDATA, pos(), undefined, undefined, undefined, undefined, data)); + }); + this._parser.on('comment', function (text, uq, pos) { + onEvent(new ParserEvent(ParserEventType.Comment, pos(), undefined, undefined, undefined, undefined, text)); + }); + if (onError) { + this._parser.on('error', function (msg, pos) { + onError(new Error(msg), pos()); + }); + } + } + Object.defineProperty(XmlParser.prototype, "angularSyntax", { + get: function () { + return this._parser.angularSyntax; + }, + set: function (value) { + this._parser.angularSyntax = value; + }, + enumerable: false, + configurable: true + }); + XmlParser.prototype.parse = function (xmlString) { + if (this._processNamespaces) { + this._namespaceStack = []; + } + this._parser.parse(xmlString); + }; + XmlParser._getNamespacesStackEntry = function (attributes) { + var stackEntry = {}; + if (!attributes) { + return stackEntry; + } + var attributeName; + var namespacePrefix; + for (var key in attributes) { + if (!attributes.hasOwnProperty(key)) { + continue; + } + attributeName = key; + if (attributeName.indexOf('xmlns') !== 0) { + continue; + } + namespacePrefix = ''; + if (attributeName.indexOf(':') !== -1) { + namespacePrefix = attributeName.split(':')[1]; + } + stackEntry[namespacePrefix] = attributes[key]; + } + return stackEntry; + }; + XmlParser.prototype._resolveNamespace = function (fullName) { + var result = { + prefix: undefined, + namespace: undefined, + name: undefined, + }; + result.prefix = ''; + if (fullName.indexOf(':') !== -1) { + var split = fullName.split(':'); + result.prefix = split[0]; + result.name = split[1]; + } + else { + result.name = fullName; + } + var stackEntry; + for (var i = this._namespaceStack.length - 1; i >= 0; i--) { + stackEntry = this._namespaceStack[i]; + for (var key in stackEntry) { + if (!stackEntry.hasOwnProperty(key)) { + continue; + } + if (result.prefix === key) { + result.namespace = stackEntry[key]; + return result; + } + } + } + return result; + }; + XmlParser._dereferenceEntities = function (s) { + s = String(s); + if (s.length > 3 && s.indexOf('&') !== -1) { + s = s.replace(_entitySearchRegEx, _HandleAmpEntities); + } + return s; + }; + return XmlParser; +}()); +exports.XmlParser = XmlParser; +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/packages/core/xml/index.ts b/packages/core/xml/index.ts index b1844d922..6dcba7e59 100644 --- a/packages/core/xml/index.ts +++ b/packages/core/xml/index.ts @@ -397,7 +397,7 @@ function _generateAmpMap(): any { } // android-specific implementation, which pre-populates the map to get it saved into the heap blob -if (global.__snapshot) { +if ((global).__snapshot) { _ampCodes = _generateAmpMap(); }