From 3b0f681f0278434c96e319b1049c7e698d175639 Mon Sep 17 00:00:00 2001 From: 4xii <975795875@qq.com> Date: Thu, 8 Sep 2022 13:49:22 +0800 Subject: [PATCH 1/7] feat:add type,symbols as helperNameMap index type --- packages/compiler-core/src/runtimeHelpers.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/compiler-core/src/runtimeHelpers.ts b/packages/compiler-core/src/runtimeHelpers.ts index 3bfe73935b8..3f5ef024797 100644 --- a/packages/compiler-core/src/runtimeHelpers.ts +++ b/packages/compiler-core/src/runtimeHelpers.ts @@ -42,8 +42,7 @@ export const IS_MEMO_SAME = Symbol(__DEV__ ? `isMemoSame` : ``) // Name mapping for runtime helpers that need to be imported from 'vue' in // generated code. Make sure these are correctly exported in the runtime! -// Using `any` here because TS doesn't allow symbols as index type. -export const helperNameMap: any = { +export const helperNameMap: Record = { [FRAGMENT]: `Fragment`, [TELEPORT]: `Teleport`, [SUSPENSE]: `Suspense`, @@ -85,7 +84,7 @@ export const helperNameMap: any = { [IS_MEMO_SAME]: `isMemoSame` } -export function registerRuntimeHelpers(helpers: any) { +export function registerRuntimeHelpers(helpers: Record) { Object.getOwnPropertySymbols(helpers).forEach(s => { helperNameMap[s] = helpers[s] }) From fa648870d10eb4fc506a6da596546eeaa5a43cab Mon Sep 17 00:00:00 2001 From: shixinzhu Date: Tue, 29 Aug 2023 14:41:39 +0800 Subject: [PATCH 2/7] feat: refactor globalsAllowList.ts to use a more comprehensive list of globally allowed values --- packages/shared/src/globalsAllowList.ts | 43 +++++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/packages/shared/src/globalsAllowList.ts b/packages/shared/src/globalsAllowList.ts index 4af518c22f1..628928760c1 100644 --- a/packages/shared/src/globalsAllowList.ts +++ b/packages/shared/src/globalsAllowList.ts @@ -1,11 +1,40 @@ import { makeMap } from './makeMap' -const GLOBALS_ALLOWED = - 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' + - 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' + - 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console' +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects +const GLOBAL_SIMPLE_VALUE = 'globalThis,Infinity,NaN,undefined' +const FUNCTION = + 'eval,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent' +const FUNDAMENTAL = 'Object,Function,Boolean,Symbol' +const ERROR = + 'Error,AggregateError,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError' +const NUMBER_AND_DATES = 'Math,BigInt,Number,Date' +const TEXT = 'String,RegExp' +const INDEXED_COLLECTIONS = + 'Array,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,BigInt64Array,BigUint64Array,Float32Array,Float64Array' +const KEYED_COLLECTIONS = 'Map,Set,WeakMap,WeakSet' +const STRUCTURED_DATA = 'ArrayBuffer,SharedArrayBuffer,DataView,Atomics,JSON' +const MANAGING_MEMORY = 'WeakRef,FinalizationRegistry' +const CONTROL_ABSTRACTION_OBJECTS = + 'Iterator,AsyncIterator,Promise,GeneratorFunction,AsyncGeneratorFunction,Generator,AsyncGenerator,AsyncFunction' +const Reflection = 'Reflect,Proxy' +const INTERNATIONALIZATION = 'Intl' +const OTHER_GLOBALS_ALLOWED = 'console' -export const isGloballyAllowed = /*#__PURE__*/ makeMap(GLOBALS_ALLOWED) +const GLOBALS_ALLOWED = [ + GLOBAL_SIMPLE_VALUE, + FUNCTION, + FUNDAMENTAL, + ERROR, + NUMBER_AND_DATES, + TEXT, + INDEXED_COLLECTIONS, + KEYED_COLLECTIONS, + STRUCTURED_DATA, + MANAGING_MEMORY, + CONTROL_ABSTRACTION_OBJECTS, + Reflection, + INTERNATIONALIZATION, + OTHER_GLOBALS_ALLOWED +].join(',') -/** @deprecated use `isGloballyAllowed` instead */ -export const isGloballyWhitelisted = isGloballyAllowed +export const isGloballyAllowed = /*#__PURE__*/ makeMap(GLOBALS_ALLOWED) From da0db8e3936cf68876c46914ea95adf70aa3e920 Mon Sep 17 00:00:00 2001 From: shixinzhu Date: Wed, 30 Aug 2023 09:59:08 +0800 Subject: [PATCH 3/7] chore: Restore isGloballyWhitelisted --- packages/shared/src/globalsAllowList.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/shared/src/globalsAllowList.ts b/packages/shared/src/globalsAllowList.ts index 628928760c1..653355c3a5b 100644 --- a/packages/shared/src/globalsAllowList.ts +++ b/packages/shared/src/globalsAllowList.ts @@ -38,3 +38,6 @@ const GLOBALS_ALLOWED = [ ].join(',') export const isGloballyAllowed = /*#__PURE__*/ makeMap(GLOBALS_ALLOWED) + +/** @deprecated use `isGloballyAllowed` instead */ +export const isGloballyWhitelisted = isGloballyAllowed From ed9ed130432d26e93df56efd8e4ff39733405d78 Mon Sep 17 00:00:00 2001 From: shixinzhu Date: Wed, 30 Aug 2023 13:21:13 +0800 Subject: [PATCH 4/7] feat: refactor globalsAllowList to use uppercase for Reflection constant --- packages/shared/src/globalsAllowList.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/shared/src/globalsAllowList.ts b/packages/shared/src/globalsAllowList.ts index 653355c3a5b..952cf2248f0 100644 --- a/packages/shared/src/globalsAllowList.ts +++ b/packages/shared/src/globalsAllowList.ts @@ -16,7 +16,7 @@ const STRUCTURED_DATA = 'ArrayBuffer,SharedArrayBuffer,DataView,Atomics,JSON' const MANAGING_MEMORY = 'WeakRef,FinalizationRegistry' const CONTROL_ABSTRACTION_OBJECTS = 'Iterator,AsyncIterator,Promise,GeneratorFunction,AsyncGeneratorFunction,Generator,AsyncGenerator,AsyncFunction' -const Reflection = 'Reflect,Proxy' +const REFLECTION = 'Reflect,Proxy' const INTERNATIONALIZATION = 'Intl' const OTHER_GLOBALS_ALLOWED = 'console' @@ -32,7 +32,7 @@ const GLOBALS_ALLOWED = [ STRUCTURED_DATA, MANAGING_MEMORY, CONTROL_ABSTRACTION_OBJECTS, - Reflection, + REFLECTION, INTERNATIONALIZATION, OTHER_GLOBALS_ALLOWED ].join(',') From 5112137b09567db9d163bc4cc91f5979f022e7d4 Mon Sep 17 00:00:00 2001 From: shixinzhu Date: Wed, 6 Sep 2023 13:15:17 +0800 Subject: [PATCH 5/7] feat: update globalsAllowList.ts with simplified global variablesThis commit removes obsolete global variables from the globalsAllowList.ts file to simplify and optimize the code --- packages/shared/src/globalsAllowList.ts | 35 ++++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/packages/shared/src/globalsAllowList.ts b/packages/shared/src/globalsAllowList.ts index 952cf2248f0..59374f5afcf 100644 --- a/packages/shared/src/globalsAllowList.ts +++ b/packages/shared/src/globalsAllowList.ts @@ -1,23 +1,29 @@ import { makeMap } from './makeMap' // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects -const GLOBAL_SIMPLE_VALUE = 'globalThis,Infinity,NaN,undefined' -const FUNCTION = - 'eval,isFinite,isNaN,parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent' -const FUNDAMENTAL = 'Object,Function,Boolean,Symbol' +const GLOBAL_SIMPLE_VALUE = 'Infinity,NaN,undefined' + const ERROR = 'Error,AggregateError,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError' -const NUMBER_AND_DATES = 'Math,BigInt,Number,Date' + +const FUNCTION = + 'isFinite,isNaN,parseFloat,parseInt,decodeURI,' + + 'decodeURIComponent,encodeURI,encodeURIComponent' + +const FUNDAMENTAL = 'Object,Boolean,Symbol' + +const NUMBER_AND_DATES = 'Math,Number,Date,BigInt' + const TEXT = 'String,RegExp' -const INDEXED_COLLECTIONS = - 'Array,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,BigInt64Array,BigUint64Array,Float32Array,Float64Array' -const KEYED_COLLECTIONS = 'Map,Set,WeakMap,WeakSet' -const STRUCTURED_DATA = 'ArrayBuffer,SharedArrayBuffer,DataView,Atomics,JSON' -const MANAGING_MEMORY = 'WeakRef,FinalizationRegistry' -const CONTROL_ABSTRACTION_OBJECTS = - 'Iterator,AsyncIterator,Promise,GeneratorFunction,AsyncGeneratorFunction,Generator,AsyncGenerator,AsyncFunction' -const REFLECTION = 'Reflect,Proxy' + +const INDEXED_COLLECTIONS = 'Array' + +const KEYED_COLLECTIONS = 'Map,Set' + +const STRUCTURED_DATA = 'JSON' + const INTERNATIONALIZATION = 'Intl' + const OTHER_GLOBALS_ALLOWED = 'console' const GLOBALS_ALLOWED = [ @@ -30,9 +36,6 @@ const GLOBALS_ALLOWED = [ INDEXED_COLLECTIONS, KEYED_COLLECTIONS, STRUCTURED_DATA, - MANAGING_MEMORY, - CONTROL_ABSTRACTION_OBJECTS, - REFLECTION, INTERNATIONALIZATION, OTHER_GLOBALS_ALLOWED ].join(',') From 4471c547558c8f1804d6eb85b6e36326962ea94c Mon Sep 17 00:00:00 2001 From: shixinzhu Date: Wed, 6 Sep 2023 14:42:46 +0800 Subject: [PATCH 6/7] feat: refactor globalsAllowList.ts for improved readability and maintainability --- packages/shared/src/globalsAllowList.ts | 60 ++++++++++--------------- 1 file changed, 23 insertions(+), 37 deletions(-) diff --git a/packages/shared/src/globalsAllowList.ts b/packages/shared/src/globalsAllowList.ts index 59374f5afcf..0b57f1bdc72 100644 --- a/packages/shared/src/globalsAllowList.ts +++ b/packages/shared/src/globalsAllowList.ts @@ -1,44 +1,30 @@ import { makeMap } from './makeMap' // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects -const GLOBAL_SIMPLE_VALUE = 'Infinity,NaN,undefined' - -const ERROR = - 'Error,AggregateError,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError' - -const FUNCTION = +const GLOBALS_ALLOWED = + // Simple Global Values + 'Infinity,NaN,undefined,' + + // Error types + 'Error,AggregateError,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,' + + // Fundamental functions 'isFinite,isNaN,parseFloat,parseInt,decodeURI,' + - 'decodeURIComponent,encodeURI,encodeURIComponent' - -const FUNDAMENTAL = 'Object,Boolean,Symbol' - -const NUMBER_AND_DATES = 'Math,Number,Date,BigInt' - -const TEXT = 'String,RegExp' - -const INDEXED_COLLECTIONS = 'Array' - -const KEYED_COLLECTIONS = 'Map,Set' - -const STRUCTURED_DATA = 'JSON' - -const INTERNATIONALIZATION = 'Intl' - -const OTHER_GLOBALS_ALLOWED = 'console' - -const GLOBALS_ALLOWED = [ - GLOBAL_SIMPLE_VALUE, - FUNCTION, - FUNDAMENTAL, - ERROR, - NUMBER_AND_DATES, - TEXT, - INDEXED_COLLECTIONS, - KEYED_COLLECTIONS, - STRUCTURED_DATA, - INTERNATIONALIZATION, - OTHER_GLOBALS_ALLOWED -].join(',') + 'decodeURIComponent,encodeURI,encodeURIComponent,' + + // Fundamental objects + 'Object,Boolean,Symbol,' + + // Numbers and dates + 'Math,Number,Date,BigInt,' + + // Text processing + 'String,RegExp,' + + // Indexed collections + 'Array,' + + // Keyed collections + 'Map,Set,' + + // Structured data + 'JSON,' + + // Internationalization & Localization + 'Intl,' + + // Other globals + 'console' export const isGloballyAllowed = /*#__PURE__*/ makeMap(GLOBALS_ALLOWED) From a321673c9301df5fb32fad14d72d8b33e8137718 Mon Sep 17 00:00:00 2001 From: shixinzhu Date: Wed, 6 Sep 2023 16:53:21 +0800 Subject: [PATCH 7/7] chore: refactor globalsAllowList.ts to include all allowed global objects and functions --- packages/shared/src/globalsAllowList.ts | 27 +++---------------------- 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/packages/shared/src/globalsAllowList.ts b/packages/shared/src/globalsAllowList.ts index 0b57f1bdc72..ca2cba60159 100644 --- a/packages/shared/src/globalsAllowList.ts +++ b/packages/shared/src/globalsAllowList.ts @@ -1,30 +1,9 @@ import { makeMap } from './makeMap' -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects const GLOBALS_ALLOWED = - // Simple Global Values - 'Infinity,NaN,undefined,' + - // Error types - 'Error,AggregateError,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,' + - // Fundamental functions - 'isFinite,isNaN,parseFloat,parseInt,decodeURI,' + - 'decodeURIComponent,encodeURI,encodeURIComponent,' + - // Fundamental objects - 'Object,Boolean,Symbol,' + - // Numbers and dates - 'Math,Number,Date,BigInt,' + - // Text processing - 'String,RegExp,' + - // Indexed collections - 'Array,' + - // Keyed collections - 'Map,Set,' + - // Structured data - 'JSON,' + - // Internationalization & Localization - 'Intl,' + - // Other globals - 'console' + 'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' + + 'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' + + 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error,Symbol' export const isGloballyAllowed = /*#__PURE__*/ makeMap(GLOBALS_ALLOWED)