-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new handling for
define:vars
scripts and styles
- Loading branch information
1 parent
963100f
commit 02b15ed
Showing
8 changed files
with
110 additions
and
36 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
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
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,25 @@ | ||
interface PropTypeSelector { | ||
[k: string]: (value: any) => any; | ||
} | ||
|
||
const propTypes: PropTypeSelector = { | ||
0: (value) => value, | ||
1: (value) => JSON.parse(value, reviver), | ||
2: (value) => new RegExp(value), | ||
3: (value) => new Date(value), | ||
4: (value) => new Map(JSON.parse(value, reviver)), | ||
5: (value) => new Set(JSON.parse(value, reviver)), | ||
6: (value) => BigInt(value), | ||
7: (value) => new URL(value), | ||
}; | ||
|
||
const reviver = (propKey: string, raw: string): any => { | ||
if (propKey === '' || !Array.isArray(raw)) return raw; | ||
if (Array.isArray(raw) && typeof raw[0] !== 'number') return JSON.stringify(raw); | ||
const [type, value] = raw; | ||
return type in propTypes ? propTypes[type](value) : undefined; | ||
}; | ||
|
||
export default function deserialize(value: string) { | ||
return JSON.parse(value, reviver); | ||
} |
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
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