-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brijesh Bittu
committed
Dec 27, 2024
1 parent
876543a
commit 7508d32
Showing
6 changed files
with
117 additions
and
54 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
11 changes: 11 additions & 0 deletions
11
packages/pigment-css-utils/src/utils/evaluateExpresions.ts
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,11 @@ | ||
/** | ||
* Slightly unsafe but way faster way to evaluate JS code than using babel transforms. | ||
* | ||
* @param expressionString The JS code expression to evaluate | ||
*/ | ||
export function evaluateClassNameArg<T>(expressionString: string): T { | ||
// Create sandbox context | ||
const context = Object.create(null); | ||
const safeEval = new Function('context', `with(context) { return ${expressionString}; }`); | ||
return safeEval(context); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './processStyle'; | ||
export * from './valueToLiteral'; | ||
export * from './parseExpressions'; | ||
export * from './evaluateExpresions'; |
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
Oops, something went wrong.