speedy-native's Introduction
speedy-native's People
speedy-native's Issues
What's this?
Is this a port of babel to rust?
tsx always true will cause error for some cases
const urlQuerys = <string>getQuery();
- This code can be correctly parsed when it is
*.ts
. - But it will failed when it is
*.tsx
.
Fix
speedy-napi should provide a config that can close tsx
parse, only use ts
SWC wasm plugin support
Intro
SWC support wasm plugin which uses swc-plugin
generated, its option like this example.
{
jsc: {
...
experimental: {
...
plugins: [ ['pluginname.wasm', pluginOptions: Record<string, any>] ]
}
}
The pluginOptions
will be stringified and transform to rust code. The rust code like this example.
use swc_plugin::{ast::Program, metadata::TransformPluginProgramMetadata, plugin_transform};
#[plugin_transform]
pub fn transform(program: Program, metadata: TransformPluginProgramMetadata) -> Program {
let config_str = metadata.get_transform_plugin_config(); // pluginOptions ---> Option<String>
let config = serde_json::from_str::<Config>(....);
...
}
reference
- SWC wasm plugin discussion: swc-project/swc#3540
- SWC wasm plugin example: @swc-project/plugins
Problem
In order to make speedy-transform
support wasm plugin. There are some problems.
- Version:
swc-plugin
gives us an ast nodeProgram
. Because we should use it asspeedy-transform
function param, we must make their package version consistent. For example, nowswc-plugin
dependsswc_ecma_ast = "=0.89.0"
. Then thespeedy-transform
's cargo.toml should use the same. - JSFunction:
swc-plugin
DO NOT support JS function, and there is no plan to try js interop at this moment. see swc-project/swc#3540 (comment). So thebabel-import
should downgrading.
{
replaceJs: {
...
replace_expr: JSFunction | String // String for wasm use
}
}
- in the wasm plugin, we can not get
Compiler
instance, which means we can not callresolver
. Butident
in AST has already havemark
. Maybe don't need to callresolver
manually. - An napi related problem: when my code have
use napi::Env
, even if I dot't use it. The wasm plugin will throw error when it runs(compile is OK). So it can't useOption(napi::Env)
. To avoid this error, I have an idea that use#cfg[target_arch="wasm32"]
to conditional compilenapi::Env
and other code related.
# error
Caused by:
0: Failed to create plugin instance
1: Error while importing "env"."napi_create_string_utf8": unknown import. Expected Function(FunctionType { params: [I32, I32, I32, I32], results: [I32] })
WIP
- make
speedy-transform
andswc-plugin
version consistent - use conditional compile to downgrade
babel-import
more detail see this branch https://github.com/speedy-js/speedy-native/tree/support-wasm
Chore
- wasm test case
- wasm package.json
- benchmark
- CI
Add license for used projects
- SWC for apache LICENSE
Contributing guide
babel-import error about importing a type
Problem
SourceCode
import { InputProps } from "antd";
{
let InputProps = 1;
console.log(InputProps);
}
function App(props: InputProps) {}
Expected result
import { InputProps } from "antd";
{
let InputProps = 1;
console.log(InputProps);
}
function App(props: InputProps) {}
Unexpected result
import "antd/es/input-props/style/index.css";
import { InputProps } from "antd/es/input-props/index.js";
{
let InputProps = 1;
console.log(InputProps);
}
function App(props: InputProps) {}
That is because babel-import not call resolve
first, which make type resolving mark
incorrectly.
How to Fix
- call
resolver
first to makemark
correctly - if a type is referenced, still remain it in origin
import
.
for example
import { InputProps, Input } from 'antd'
should be
import "antd/es/input/style/index.css";
import Input from "antd/es/input/index.js";
import { InputProps } from 'antd'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.