fix: global declarations fix (#10247)

This commit is contained in:
farfromrefuge
2023-03-23 17:55:38 +00:00
committed by GitHub
parent 7edd21a688
commit 2f4c318276
16 changed files with 118 additions and 119 deletions

View File

@@ -19,7 +19,7 @@ export function testInitialized() {
export function testDisplayedEvent() { export function testDisplayedEvent() {
// global.isDisplayedEventFired flag is set in app.ts application.displayedEvent handler // global.isDisplayedEventFired flag is set in app.ts application.displayedEvent handler
TKUnit.assert((<any>global).isDisplayedEventFired, 'application.displayedEvent not fired'); TKUnit.assert(global.isDisplayedEventFired, 'application.displayedEvent not fired');
} }
export function testOrientation() { export function testOrientation() {

View File

@@ -6,8 +6,8 @@ export function test_global_system_import() {
TKUnit.assert(System, 'System not defined'); TKUnit.assert(System, 'System not defined');
TKUnit.assert(typeof System.import === 'function', 'System.import not a function'); TKUnit.assert(typeof System.import === 'function', 'System.import not a function');
TKUnit.assert((<any>global).System, 'global.System not defined'); TKUnit.assert(global.System, 'global.System not defined');
TKUnit.assert(typeof (<any>global).System.import === 'function', 'global.System.import not a function'); TKUnit.assert(typeof global.System.import === 'function', 'global.System.import not a function');
} }
export function test_global_zonedCallback() { export function test_global_zonedCallback() {

View File

@@ -249,7 +249,7 @@ function _test_onLiveSync_ModalViewClosed(context: ModuleContext) {
} }
function livesync(context: ModuleContext) { function livesync(context: ModuleContext) {
const ls = (<any>global).__coreModulesLiveSync || global.__onLiveSync; const ls = global.__coreModulesLiveSync || global.__onLiveSync;
ls(context); ls(context);
} }

View File

@@ -16,7 +16,7 @@ if (Application.ios) {
// Common events for both Android and iOS. // Common events for both Android and iOS.
Application.on(Application.displayedEvent, function (args: ApplicationEventData) { Application.on(Application.displayedEvent, function (args: ApplicationEventData) {
(<any>global).isDisplayedEventFired = true; global.isDisplayedEventFired = true;
if (args.android) { if (args.android) {
// For Android applications, args.android is an Android activity class. // For Android applications, args.android is an Android activity class.

View File

@@ -130,7 +130,7 @@ export function test_loadWithAttributes() {
} }
export function test_parse_ShouldNotCrashWithoutExports() { export function test_parse_ShouldNotCrashWithoutExports() {
const xml = (<any>global).loadModule('xml-declaration/mainPage.xml', true); const xml = global.loadModule('xml-declaration/mainPage.xml', true);
var v: View = Builder.parse(xml); var v: View = Builder.parse(xml);
TKUnit.assert(v instanceof View, 'Expected result: View; Actual result: ' + v + ';'); TKUnit.assert(v instanceof View, 'Expected result: View; Actual result: ' + v + ';');
@@ -826,7 +826,7 @@ export function test_NonExistingElementInTemplateError() {
} }
export function test_EventInTemplate() { export function test_EventInTemplate() {
var pageCode = (<any>global).loadModule('xml-declaration/template-builder-tests/event-in-template', true); var pageCode = global.loadModule('xml-declaration/template-builder-tests/event-in-template', true);
var notified = false; var notified = false;
pageCode.test = (args) => { pageCode.test = (args) => {
notified = true; notified = true;
@@ -849,7 +849,7 @@ export function test_EventInTemplate() {
} }
export function test_EventInCodelessFragment() { export function test_EventInCodelessFragment() {
var pageCode = (<any>global).loadModule('./xml-declaration/template-builder-tests/event-in-codeless-fragment', true); var pageCode = global.loadModule('./xml-declaration/template-builder-tests/event-in-codeless-fragment', true);
var notified = false; var notified = false;
pageCode.setCallback((args) => { pageCode.setCallback((args) => {

View File

@@ -11,7 +11,7 @@ var countResume = 0;
var countSuspend = 0; var countSuspend = 0;
Application.on('displayed', (args) => { Application.on('displayed', (args) => {
const uptime = global.android ? (<any>org).nativescript.Process.getUpTime : (<any>global).__tns_uptime; const uptime = global.android ? (<any>org).nativescript.Process.getUpTime : global.__tns_uptime;
console.log('Startup time: ' + uptime() + 'ms.'); console.log('Startup time: ' + uptime() + 'ms.');
}); });

View File

@@ -295,9 +295,9 @@ function setup(parent?: LayoutBase): Label {
function time(): number { function time(): number {
if (global.android) { if (global.android) {
return (<any>global).java.lang.System.nanoTime() / 1000000; return global.java.lang.System.nanoTime() / 1000000;
} else { } else {
return (<any>global).CACurrentMediaTime() * 1000; return global.CACurrentMediaTime() * 1000;
} }
} }

View File

@@ -407,7 +407,7 @@ export function ensureNativeApplication() {
} }
// attach on global, so it can be overwritten in NativeScript Angular // attach on global, so it can be overwritten in NativeScript Angular
(<any>global).__onLiveSyncCore = function (context?: ModuleContext) { global.__onLiveSyncCore = function (context?: ModuleContext) {
ensureNativeApplication(); ensureNativeApplication();
iosApp._onLivesync(context); iosApp._onLivesync(context);
}; };

View File

@@ -27,7 +27,7 @@ export class FPSCallback implements definition.FPSCallback {
} }
private _isNativeFramesSupported() { private _isNativeFramesSupported() {
return typeof (<any>global).__postFrameCallback === 'function' && typeof (<any>global).__removeFrameCallback === 'function'; return typeof (global as any).__postFrameCallback === 'function' && typeof global.__removeFrameCallback === 'function';
} }
public start() { public start() {

View File

@@ -17,10 +17,9 @@ declare interface NativeScriptError extends Error {
} }
//Augment the NodeJS global type with our own extensions //Augment the NodeJS global type with our own extensions
declare namespace NodeJS { declare module globalThis {
interface Global { var NativeScriptHasInitGlobal: boolean;
NativeScriptHasInitGlobal?: boolean; var NativeScriptGlobals: {
NativeScriptGlobals?: {
/** /**
* Global framework event handling * Global framework event handling
*/ */
@@ -39,12 +38,12 @@ declare namespace NodeJS {
*/ */
addEventWiring(callback: () => void): void; addEventWiring(callback: () => void): void;
}; };
android?: any; // var android: any;
require(id: string): any; function require(id: string): any;
moduleMerge(sourceExports: any, destExports: any): void; function moduleMerge(sourceExports: any, destExports: any): void;
registerModule(name: string, loader: (name: string) => any): void; function registerModule(name: string, loader: (name: string) => any): void;
/** /**
* Register all modules from a webpack context. * Register all modules from a webpack context.
* The context is one created using the following webpack utility: * The context is one created using the following webpack utility:
@@ -58,7 +57,7 @@ declare namespace NodeJS {
* Will resolve lookups for .js to the .ts file. * Will resolve lookups for .js to the .ts file.
* By default scss and ts files are mapped. * By default scss and ts files are mapped.
*/ */
registerWebpackModules(context: { keys(): string[]; (key: string): any }, extensionMap?: { [originalFileExtension: string]: string }); function registerWebpackModules(context: { keys(): string[]; (key: string): any }, extensionMap?: { [originalFileExtension: string]: string });
/** /**
* The NativeScript XML builder, style-scope, application modules use various resources such as: * The NativeScript XML builder, style-scope, application modules use various resources such as:
@@ -72,7 +71,7 @@ declare namespace NodeJS {
* When adding resolvers at the start of the array, avoid throwing and return null instead so subsequent resolvers may try to resolve the resource. * 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. * 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[]; var moduleResolvers: ModuleResolver[];
/** /**
* *
@@ -81,42 +80,43 @@ declare namespace NodeJS {
* Xml, css/scss and js/ts modules for pages and custom-components should load with loadForUI=true. * 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. * Passing "true" will enable the HMR mechanics this module. Default value is false.
*/ */
loadModule(name: string, loadForUI?: boolean): any; function loadModule(name: string, loadForUI?: boolean): any;
/** /**
* Checks if the module has been registered with `registerModule` or in `registerWebpackModules` * Checks if the module has been registered with `registerModule` or in `registerWebpackModules`
* @param name Name of the module * @param name Name of the module
*/ */
moduleExists(name: string): boolean; function moduleExists(name: string): boolean;
getRegisteredModules(): string[]; function getRegisteredModules(): string[];
_unregisterModule(name: string): void; function _unregisterModule(name: string): void;
_isModuleLoadedForUI(moduleName: string): boolean; function _isModuleLoadedForUI(moduleName: string): boolean;
onGlobalLayoutListener: any; var onGlobalLayoutListener: any;
zonedCallback(callback: Function): Function; function zonedCallback(callback: Function): Function;
Reflect?: any; var Reflect: any;
Deprecated(target: Object, key?: string | symbol, descriptor?: any): any; function Deprecated(target: Object, key?: string | symbol, descriptor?: any): any;
Experimental(target: Object, key?: string | symbol, descriptor?: any): any; function Experimental(target: Object, key?: string | symbol, descriptor?: any): any;
__native?: any; var __native: any;
__inspector?: any; var __inspector: any;
__extends: any; var __extends: any;
__onLiveSync: (context?: { type: string; path: string }) => void; var __onLiveSync: (context?: { type: string; path: string }) => void;
__onLiveSyncCore: (context?: { type: string; path: string }) => void; var __onLiveSyncCore: (context?: { type: string; path: string }) => void;
__onUncaughtError: (error: NativeScriptError) => void; var __onUncaughtError: (error: NativeScriptError) => void;
__onDiscardedError: (error: NativeScriptError) => void; var __onDiscardedError: (error: NativeScriptError) => void;
__snapshot?: boolean; var __snapshot: boolean;
TNS_WEBPACK?: boolean; var TNS_WEBPACK: boolean;
isIOS?: boolean; var isIOS: boolean;
isAndroid?: boolean; var isAndroid: boolean;
__requireOverride?: (name: string, dir: string) => any; var isDisplayedEventFired: boolean;
var autoLoadPolyfills: boolean;
var __requireOverride: (name: string, dir: string) => any;
// used to get the rootlayout instance to add/remove childviews // used to get the rootlayout instance to add/remove childviews
rootLayout: any; var rootLayout: any;
}
} }
declare const __DEV__: boolean; declare const __DEV__: boolean;
declare const __CSS_PARSER__: string; declare const __CSS_PARSER__: string;

View File

@@ -115,8 +115,8 @@ export function initGlobal() {
// ts-helpers // ts-helpers
// Required by V8 snapshot generator // Required by V8 snapshot generator
if (!(<any>global).__extends) { if (!global.__extends) {
(<any>global).__extends = function (d, b) { global.__extends = function (d, b) {
for (const p in b) { for (const p in b) {
if (b.hasOwnProperty(p)) { if (b.hasOwnProperty(p)) {
d[p] = b[p]; d[p] = b[p];
@@ -160,7 +160,7 @@ export function initGlobal() {
}; };
// Cast to <any> because moduleResolvers is read-only in definitions // Cast to <any> because moduleResolvers is read-only in definitions
(<any>global).moduleResolvers = [global.require]; global.moduleResolvers = [global.require];
global.registerModule = function (name: string, loader: ModuleLoader): void { global.registerModule = function (name: string, loader: ModuleLoader): void {
modules.set(name, { loader, moduleId: name }); modules.set(name, { loader, moduleId: name });
@@ -250,7 +250,7 @@ export function initGlobal() {
return result; return result;
} }
for (const resolver of (<any>global).moduleResolvers) { for (const resolver of global.moduleResolvers) {
const result = resolver(name); const result = resolver(name);
if (result) { if (result) {
modules.set(name, { moduleId: name, loader: () => result }); modules.set(name, { moduleId: name, loader: () => result });
@@ -276,19 +276,19 @@ export function initGlobal() {
}; };
global.zonedCallback = function (callback: Function): Function { global.zonedCallback = function (callback: Function): Function {
if ((<any>global).zone) { if (global.zone) {
// Zone v0.5.* style callback wrapping // Zone v0.5.* style callback wrapping
return (<any>global).zone.bind(callback); return global.zone.bind(callback);
} }
if ((<any>global).Zone) { if (global.Zone) {
// Zone v0.6.* style callback wrapping // Zone v0.6.* style callback wrapping
return (<any>global).Zone.current.wrap(callback); return global.Zone.current.wrap(callback);
} else { } else {
return callback; return callback;
} }
}; };
(<any>global).System = { global.System = {
import(path) { import(path) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {

View File

@@ -2,13 +2,13 @@
declare let __startCPUProfiler: any; declare let __startCPUProfiler: any;
declare let __stopCPUProfiler: any; declare let __stopCPUProfiler: any;
export function uptime() { export function uptime(): number {
return global.android ? (<any>org).nativescript.Process.getUpTime() : (<any>global).__tns_uptime(); return global.android ? (<any>org).nativescript.Process.getUpTime() : global.__tns_uptime();
} }
export function log(message: string, ...optionalParams: any[]): void { export function log(message: string, ...optionalParams: any[]): void {
if ((<any>global).__nslog) { if (global.__nslog) {
(<any>global).__nslog('CONSOLE LOG: ' + message); global.__nslog('CONSOLE LOG: ' + message);
} }
console.log(message, ...optionalParams); console.log(message, ...optionalParams);
} }
@@ -31,7 +31,7 @@ const timers: { [index: string]: TimerInfo } = {};
const anyGlobal = <any>global; const anyGlobal = <any>global;
const profileNames: string[] = []; const profileNames: string[] = [];
export const time = (<any>global).__time || Date.now; export const time = (global.__time || Date.now) as () => number;
export function start(name: string): void { export function start(name: string): void {
let info = timers[name]; let info = timers[name];

View File

@@ -4,7 +4,6 @@
"noEmitOnError": true, "noEmitOnError": true,
"noEmitHelpers": true, "noEmitHelpers": true,
"declaration": true, "declaration": true,
"noImplicitAny": false,
"noImplicitUseStrict": true, "noImplicitUseStrict": true,
"removeComments": false, "removeComments": false,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,

View File

@@ -34,7 +34,7 @@ class AnimationDelegateImpl extends NSObject implements CAAnimationDelegate {
public nextAnimation: Function; public nextAnimation: Function;
// The CAAnimationDelegate protocol has been introduced in the iOS 10 SDK // The CAAnimationDelegate protocol has been introduced in the iOS 10 SDK
static ObjCProtocols = (<any>global).CAAnimationDelegate ? [(<any>global).CAAnimationDelegate] : []; static ObjCProtocols = global.CAAnimationDelegate ? [global.CAAnimationDelegate] : [];
private _finishedCallback: Function; private _finishedCallback: Function;
private _propertyAnimation: PropertyAnimationInfo; private _propertyAnimation: PropertyAnimationInfo;

View File

@@ -597,7 +597,7 @@ export function reloadPage(context?: ModuleContext): void {
} }
// attach on global, so it can be overwritten in NativeScript Angular // attach on global, so it can be overwritten in NativeScript Angular
(<any>global).__onLiveSyncCore = Frame.reloadPage; global.__onLiveSyncCore = Frame.reloadPage;
function cloneExpandedTransitionListener(expandedTransitionListener: any) { function cloneExpandedTransitionListener(expandedTransitionListener: any) {
if (!expandedTransitionListener) { if (!expandedTransitionListener) {

View File

@@ -397,7 +397,7 @@ function _generateAmpMap(): any {
} }
// android-specific implementation, which pre-populates the map to get it saved into the heap blob // android-specific implementation, which pre-populates the map to get it saved into the heap blob
if ((<any>global).__snapshot) { if (global.__snapshot) {
_ampCodes = _generateAmpMap(); _ampCodes = _generateAmpMap();
} }