@@ -57,7 +57,7 @@ export function createSizingProperty<T extends CSSValue>(values: PropertyValueMa
57
57
return [ { [ property ] : value } , valueMap . get ( value ) ! ] ;
58
58
} ) ;
59
59
}
60
-
60
+
61
61
if ( typeof value === 'number' ) {
62
62
let cssValue = value === 0 ? '0px' : fn ( value ) ;
63
63
return { default : [ { [ property ] : cssValue } , generateName ( value + valueMap . size ) ] } ;
@@ -630,6 +630,14 @@ function getStaticClassName(rules: Rule[]): string {
630
630
}
631
631
632
632
export function raw ( this : MacroContext | void , css : string , layer = '_.a' ) {
633
+ // Check if `this` is undefined, which means style was not called as a macro but as a normal function.
634
+ // We also check if this is globalThis, which happens in non-strict mode bundles.
635
+ // Also allow style to be called as a normal function in tests.
636
+ // @ts -ignore
637
+ // eslint-disable-next-line
638
+ if ( ( this == null || this === globalThis ) && process . env . NODE_ENV !== 'test' ) {
639
+ throw new Error ( 'The raw macro must be imported with {type: "macro"}.' ) ;
640
+ }
633
641
let className = generateArbitraryValueSelector ( css , true ) ;
634
642
css = `@layer ${ layer } {
635
643
.${ className } {
@@ -646,6 +654,14 @@ export function raw(this: MacroContext | void, css: string, layer = '_.a') {
646
654
}
647
655
648
656
export function keyframes ( this : MacroContext | void , css : string ) {
657
+ // Check if `this` is undefined, which means style was not called as a macro but as a normal function.
658
+ // We also check if this is globalThis, which happens in non-strict mode bundles.
659
+ // Also allow style to be called as a normal function in tests.
660
+ // @ts -ignore
661
+ // eslint-disable-next-line
662
+ if ( ( this == null || this === globalThis ) && process . env . NODE_ENV !== 'test' ) {
663
+ throw new Error ( 'The keyframes macro must be imported with {type: "macro"}.' ) ;
664
+ }
649
665
let name = generateArbitraryValueSelector ( css , true ) ;
650
666
css = `@keyframes ${ name } {
651
667
${ css }
0 commit comments