Codex
Codex
Explore posts from servers
SCSWC Community
Created by Codex on 4/22/2025 in #questions
Use `swc_ecma_compat_es2017::async_to_generator` for conditional async transformations
Hey team, I've been working on a plugin that takes async functions and transforms them to generators for usage with mobx flows. I've gotten reasonably far but came across: https://docs.rs/swc_ecma_compat_es2017/latest/src/swc_ecma_compat_es2017/async_to_generator.rs.html#39-46 This transformation is exactly what i've been aiming for and would make for a far more robust solution, as what i've written so far handles the conditional cases as I expect. The issue i'm running into is that I'd like to instantiate the AsyncToGenerator visitor to visit_children_with it when the conditions are met to perform this transformation, but async_to_generator returns Pass which does not satisfy VisitMut Would it be reasonable to export a function that does work this way from swc_ecma_compat_es2017? Or am I down the wrong path here?
4 replies
CDCloudflare Developers
Created by Codex on 6/20/2024 in #workers-help
K6 load testing and 429s
Hey team Currently been working on load testing a simple worker (just a JS 10 liner kind of deal) we have (non-free/ent tier) and have found that when trying to perform load testing using K6 we begin to see a flood of 429's I did find this post: https://community.cloudflare.com/t/can-requests-to-workers-get-rate-limited/435598/2 Which suggests i'm encountering on paid it defends against a small amount of IPs sending too many requests But I cannot seem to find a ways to configure either whitelisting the IP's i'm using or to temporarily disable this throttling feature. Where can I find more information about this? Is there configuration I can see either on the worker level or in the portal around this?
13 replies
SCSWC Community
Created by Codex on 12/11/2023 in #questions
Folder import resulting in undefined
Having a tonne of trouble with trying to get swc working with jest as doing a folder import results in an empty object:
import * as x from '..';
import * as x from '..';
->
{__esModule: true}
{__esModule: true}
swcrc:
{
"$schema": "http://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"transform": {
"react": {
"runtime": "automatic"
}
},
"experimental": {
"plugins": [
[
"@swc/plugin-emotion",
{
"autoLabel": "always"
}
]
]
}
}
}
{
"$schema": "http://json.schemastore.org/swcrc",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"transform": {
"react": {
"runtime": "automatic"
}
},
"experimental": {
"plugins": [
[
"@swc/plugin-emotion",
{
"autoLabel": "always"
}
]
]
}
}
}
tsconfig:
{
"compilerOptions": {
"target": "es2022",
"module": "esnext",
"composite": true,
"incremental": true,
"noEmit": true,
"pretty": true,
"sourceMap": true,

"lib": ["dom", "dom.iterable", "esnext"],

"strict": true,

"allowSyntheticDefaultImports": true,
"downlevelIteration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"jsxImportSource": "@emotion/react",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"useDefineForClassFields": true
}
}
{
"compilerOptions": {
"target": "es2022",
"module": "esnext",
"composite": true,
"incremental": true,
"noEmit": true,
"pretty": true,
"sourceMap": true,

"lib": ["dom", "dom.iterable", "esnext"],

"strict": true,

"allowSyntheticDefaultImports": true,
"downlevelIteration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"jsxImportSource": "@emotion/react",
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"useDefineForClassFields": true
}
}
What am I doing wrong 🤔
1 replies
SCSWC Community
Created by Codex on 7/6/2023 in #questions
Transforming `import.meta` with jest and swc
I've spent a few hours trying to find how this is meant to work with jest and swc. config:
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true
},
"transform": {
"react": {
"runtime": "automatic",
"importSource": "@emotion/react"
}
}
},
"isModule": true
}
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true
},
"transform": {
"react": {
"runtime": "automatic",
"importSource": "@emotion/react"
}
}
},
"isModule": true
}
Jest:
/// <reference types="node" />

const config = JSON.parse(fs.readFileSync(`${process.cwd()}/.swcrc`, 'utf-8'))
delete config.exclude
config.swcrc = false
config.jsc.transform.hidden = {
...config.jsc.transform.hidden,
jest: true
}

/**
* @type { import("jest").Config }
*/
module.exports = {
roots: ['<rootDir>/src/', '<rootDir>/test/'],
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
snapshotSerializers: ['@emotion/jest/serializer'],
testEnvironment: 'jsdom',
testEnvironmentOptions: { url: 'http://localhost/' },
testRegex: '(test|spec).tsx?$',
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest', config]
}
}
/// <reference types="node" />

const config = JSON.parse(fs.readFileSync(`${process.cwd()}/.swcrc`, 'utf-8'))
delete config.exclude
config.swcrc = false
config.jsc.transform.hidden = {
...config.jsc.transform.hidden,
jest: true
}

/**
* @type { import("jest").Config }
*/
module.exports = {
roots: ['<rootDir>/src/', '<rootDir>/test/'],
setupFilesAfterEnv: ['<rootDir>/src/setupTests.ts'],
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
snapshotSerializers: ['@emotion/jest/serializer'],
testEnvironment: 'jsdom',
testEnvironmentOptions: { url: 'http://localhost/' },
testRegex: '(test|spec).tsx?$',
transform: {
'^.+\\.(t|j)sx?$': ['@swc/jest', config]
}
}
But no matter what I try, I still hit: SyntaxError: Cannot use 'import.meta' outside a module What am I doing wrong here?
4 replies
SCSWC Community
Created by Codex on 4/10/2023 in #questions
OOM with emotion plugin?
I was looking at adopting swc with the emotion plugin in one of our repositories when I hit this:
Caused by:
0: failed to invoke `@swc/plugin-emotion` as js transform plugin at ../../node_modules/@swc/plugin-emotion/swc_plugin_emotion.wasm
1: RuntimeError: out of bounds memory access
2: heap_get_oob', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc-0.260.1/src/plugin.rs:228:14
failed to handle: failed to invoke plugin: failed to invoke plugin on 'Some("src/components/x.tsx")'
Caused by:
0: failed to invoke `@swc/plugin-emotion` as js transform plugin at ../../node_modules/@swc/plugin-emotion/swc_plugin_emotion.wasm
1: RuntimeError: out of bounds memory access
2: heap_get_oob', /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc-0.260.1/src/plugin.rs:228:14
failed to handle: failed to invoke plugin: failed to invoke plugin on 'Some("src/components/x.tsx")'
35 replies