Coder Social home page Coder Social logo

speedy-native's Introduction

speedy-native's People

Contributors

h-a-n-a avatar iwanabethatguy avatar konicyqwq avatar zhusjfaker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

speedy-native's Issues

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

Problem

In order to make speedy-transform support wasm plugin. There are some problems.

  1. Version: swc-plugin gives us an ast node Program. Because we should use it as speedy-transform function param, we must make their package version consistent. For example, now swc-plugin depends swc_ecma_ast = "=0.89.0". Then the speedy-transform's cargo.toml should use the same.
  2. 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 the babel-import should downgrading.
{
    replaceJs: {
        ...
        replace_expr: JSFunction | String // String for wasm use
    }
}
  1. in the wasm plugin, we can not get Compiler instance, which means we can not call resolver. But ident in AST has already have mark. Maybe don't need to call resolver manually.
  2. 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 use Option(napi::Env). To avoid this error, I have an idea that use #cfg[target_arch="wasm32"] to conditional compile napi::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 and swc-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

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 make mark 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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.