From bcca475dbc58d76434cd8120b94929758cee2825 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 30 Nov 2023 09:39:40 +0100 Subject: [PATCH] feat(compiler-core): support accessing Error as global in template expressions (#7018) --- .../__tests__/transforms/transformExpressions.spec.ts | 8 ++++++++ packages/shared/src/globalsAllowList.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts index 0d18c1bebe5..a9697930c95 100644 --- a/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts +++ b/packages/compiler-core/__tests__/transforms/transformExpressions.spec.ts @@ -161,6 +161,14 @@ describe('compiler: expression transform', () => { type: NodeTypes.COMPOUND_EXPRESSION, children: [{ content: `Math` }, `.`, { content: `max` }, `(1, 2)`] }) + + expect( + (parseWithExpressionTransform(`{{ new Error() }}`) as InterpolationNode) + .content + ).toMatchObject({ + type: NodeTypes.COMPOUND_EXPRESSION, + children: ['new ', { content: 'Error' }, '()'] + }) }) test('should not prefix reserved literals', () => { diff --git a/packages/shared/src/globalsAllowList.ts b/packages/shared/src/globalsAllowList.ts index 4af518c22f1..210650e3e2b 100644 --- a/packages/shared/src/globalsAllowList.ts +++ b/packages/shared/src/globalsAllowList.ts @@ -3,7 +3,7 @@ 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' + 'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,console,Error' export const isGloballyAllowed = /*#__PURE__*/ makeMap(GLOBALS_ALLOWED)