Skip to content

Conversation

@kdy1
Copy link
Member

@kdy1 kdy1 commented Mar 28, 2025

Description:

A JS API is required to use it from JS world.

import { experimental_analyze } as '@swc/core';

const result = await analyze(
	`console.log('boo')`,
	{
	    plugins: [[getPluginAbsolutePath(feature), {}]],
	}
);

expect(result).toMatchInlineSnapshot(
    `"{"test":"test"}"`
);

Wasm plugin code:

use swc_core::{
    ecma::ast::Program,
    plugin::{plugin_transform, proxies::TransformPluginProgramMetadata},
    transform_common::output::experimental_emit,
};

#[plugin_transform]
pub fn process(program: Program, _metadata: TransformPluginProgramMetadata) -> Program {
    experimental_emit("test".into(), "test".into());

    program
}

Related issue:

@changeset-bot
Copy link

changeset-bot bot commented Mar 28, 2025

🦋 Changeset detected

Latest commit: dedc6ef

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member Author

kdy1 commented Mar 28, 2025

@kdy1 kdy1 changed the title Dep feat(plugin): Add extra output API Mar 28, 2025
@kdy1 kdy1 marked this pull request as ready for review March 28, 2025 10:36
@kdy1 kdy1 requested a review from a team as a code owner March 28, 2025 10:36
@kdy1 kdy1 marked this pull request as draft March 28, 2025 10:36
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 28, 2025

CodSpeed Performance Report

Merging #10288 will degrade performances by 1.05%

Comparing kdy1/analyzer-proxy-api (dedc6ef) with main (d213a84)

Summary

⚡ 1 improvements
❌ 1 regressions
✅ 150 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
serialization of serde 2.8 µs 2.8 µs -1.05%
es/lints/libs/terser 29.8 ms 29.2 ms +2.16%

@kdy1 kdy1 force-pushed the kdy1/analyzer-proxy-api branch from a6ce558 to 88cccf9 Compare March 29, 2025 02:18
@kdy1 kdy1 force-pushed the kdy1/analyzer-api branch from f216351 to 9599a0b Compare March 29, 2025 02:18
@kdy1 kdy1 changed the title feat(plugin): Add extra output API feat(plugin): Refactor extra output API and expose it to Wasm plugin Mar 29, 2025
@kdy1 kdy1 force-pushed the kdy1/analyzer-proxy-api branch from 81039ba to 88c53f1 Compare March 29, 2025 03:49
@kdy1 kdy1 force-pushed the kdy1/analyzer-api branch from 5a4855a to a65a781 Compare March 29, 2025 03:49
@kdy1 kdy1 force-pushed the kdy1/analyzer-proxy-api branch from 6c5f82e to 4704673 Compare March 31, 2025 02:54
Base automatically changed from kdy1/analyzer-api to main March 31, 2025 05:16
@kdy1 kdy1 force-pushed the kdy1/analyzer-proxy-api branch from 4704673 to 36c509d Compare March 31, 2025 05:17
**Description:**

A JS API is required to use it from JS world.

```js
import { experimental_analyze } as '@swc/core';

const result = await analyze(
	`console.log('boo')`,
	{
	    plugins: [[getPluginAbsolutePath(feature), {}]],
	}
);

expect(result).toMatchInlineSnapshot(
    `"{"test":"test"}"`
);


```

Wasm plugin code:

```rust
use swc_core::{
    ecma::ast::Program,
    plugin::{plugin_transform, proxies::TransformPluginProgramMetadata},
    transform_common::output::experimental_emit,
};

#[plugin_transform]
pub fn process(program: Program, _metadata: TransformPluginProgramMetadata) -> Program {
    experimental_emit("test".into(), "test".into());

    program
}


```
@kdy1 kdy1 changed the title feat(plugin): Refactor extra output API and expose it to Wasm plugin feat(plugin): Add analysis APIs Mar 31, 2025
@kdy1 kdy1 changed the title feat(plugin): Add analysis APIs feat(es): Add analysis APIs Mar 31, 2025
@kdy1 kdy1 marked this pull request as ready for review March 31, 2025 05:19
@kdy1 kdy1 requested a review from a team as a code owner March 31, 2025 05:19
kodiakhq[bot]
kodiakhq bot previously approved these changes Mar 31, 2025
@kdy1 kdy1 changed the title feat(es): Add analysis APIs feat(es): Add analysis API and refactor output API Mar 31, 2025
@kdy1 kdy1 enabled auto-merge (squash) March 31, 2025 05:21
@kdy1 kdy1 disabled auto-merge March 31, 2025 05:23
kodiakhq[bot]
kodiakhq bot previously approved these changes Mar 31, 2025
kodiakhq[bot]
kodiakhq bot previously approved these changes Mar 31, 2025
@kdy1 kdy1 enabled auto-merge (squash) March 31, 2025 05:33
kodiakhq[bot]
kodiakhq bot previously approved these changes Mar 31, 2025
kodiakhq[bot]
kodiakhq bot previously approved these changes Mar 31, 2025
@kdy1 kdy1 merged commit a53c60d into main Mar 31, 2025
166 checks passed
@kdy1 kdy1 deleted the kdy1/analyzer-proxy-api branch March 31, 2025 07:22
@kdy1 kdy1 self-assigned this Mar 31, 2025
@kdy1 kdy1 modified the milestones: Planned, v1.11.14 Mar 31, 2025
@swc-project swc-project locked as resolved and limited conversation to collaborators Apr 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

API to collect Extra Data from Wasm plugins and custom transforms

2 participants