forked from vuejs/vue
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(compiler): Allow BigInt usage in templates (issue vuejs#11126)
- Loading branch information
1 parent
6390f70
commit a22d5a3
Showing
6 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* @flow */ | ||
|
||
/** | ||
* turn "1000n" into "BigInt(1000)" | ||
* and then turn "BigInt(1000)" into "_bigInt(1000)" | ||
* | ||
* by the way, if we meet variable like "l18n" | ||
* we will change "l18n" to "l18@" | ||
* after we finish parse bigint | ||
* we will change "l18@" back to "l18n" | ||
* @param {*} exp | ||
*/ | ||
export function parseBigint(exp: string): string { | ||
let expression = exp | ||
.replace(/([a-zA-Z_$]+[0-9]+)n/g, '$1@') | ||
.replace(/([0-9]+)n/g, 'BigInt($1)') | ||
.replace(/([a-zA-Z_$]+[0-9]+)@/g, '$1n') | ||
.replace(/BigInt\(/g, '_bigInt(') | ||
return expression | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* @flow */ | ||
import { warn } from 'core/util/index' | ||
/** | ||
* get BigInt function | ||
* if the browser support window.BigInt, we will use it | ||
* if not, we can customize BigInt() for vue | ||
*/ | ||
export function getBigintFunc (): Function { | ||
if (typeof window !== 'undefined' && typeof window.BigInt === 'function') { | ||
return window.BigInt | ||
} else if (typeof global !== 'undefined' && typeof global.BigInt === 'function') { | ||
return global.BigInt | ||
} else { | ||
warn( | ||
'BigInt is not support!' | ||
) | ||
// customize our own BigInt() function | ||
return function (arg) { | ||
return arg | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters