Skip to content

Commit

Permalink
feat(compiler): add support for Error global
Browse files Browse the repository at this point in the history
Related to #7015
  • Loading branch information
posva authored and yyx990803 committed Oct 20, 2023
1 parent 4162311 commit e26d024
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,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', () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/shared/src/globalsWhitelist.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { makeMap } from './makeMap'

const GLOBALS_WHITE_LISTED =
'Infinity,undefined,NaN,isFinite,isNaN,parseFloat,parseInt,decodeURI,' +
'decodeURIComponent,encodeURI,encodeURIComponent,Math,Number,Date,Array,' +
'Object,Boolean,String,RegExp,Map,Set,JSON,Intl,BigInt,Error'

export const isGloballyWhitelisted = /*#__PURE__*/ makeMap(GLOBALS_WHITE_LISTED)

0 comments on commit e26d024

Please sign in to comment.