Skip to content

Commit

Permalink
fix: reflection, lazy imports, esmodule interop and others
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed Oct 31, 2023
1 parent 60530d9 commit 13548c3
Show file tree
Hide file tree
Showing 24 changed files with 1,579 additions and 505 deletions.
4 changes: 4 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[target.wasm32-unknown-unknown]
rustflags = [
"-C", "link-args=-z stack-size=4194304",
]
152 changes: 76 additions & 76 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,91 +1,91 @@
name: Test Suite

on:
push:
branches:
- develop
pull_request_target:
push:
branches:
- develop
pull_request_target:

jobs:
test_rust:
name: Test Rust
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Checkout source
test_rust:
name: Test Rust
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Checkout source

- uses: actions/cache@v3
name: Setup Cache
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
simd-target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: actions/cache@v3
name: Setup Cache
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
simd-target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Run Rust tests
run: |
cargo install grcov
npm install -g mocha
npm ci
cargo clean
cargo test
grcov . --binary-path ./target/debug -s . -t lcov --branch -o ./coverage.lcov
env:
RUSTFLAGS: -Cinstrument-coverage
LLVM_PROFILE_FILE: "%p-%m.profraw"
- name: Run Rust tests
run: |
cargo install grcov
npm install -g mocha
npm ci
cargo clean
cargo test
grcov . --binary-path ./target/debug -s . -t lcov --branch -o ./coverage.lcov
env:
RUSTFLAGS: -Cinstrument-coverage
LLVM_PROFILE_FILE: '%p-%m.profraw'

- name: Publish coverage report
uses: codecov/codecov-action@v3
with:
file: ./coverage.lcov
- name: Publish coverage report
uses: codecov/codecov-action@v3
with:
file: ./coverage.lcov

test_node:
name: Test (Node.JS ${{ matrix.node_version }})
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [16, 18, 20]
fail-fast: false
test_node:
name: Test (Node.JS ${{ matrix.node_version }})
runs-on: ubuntu-latest
strategy:
matrix:
node_version: [16, 18, 20]
fail-fast: false

steps:
- uses: actions/checkout@v4
name: Checkout source
steps:
- uses: actions/checkout@v4
name: Checkout source

- uses: actions/cache@v3
name: Setup Cache
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
simd-target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: actions/cache@v3
name: Setup Cache
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
simd-target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}

- uses: actions/cache@v3
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
- uses: actions/cache@v3
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}

- uses: actions/setup-node@v3
name: Setup Node.JS
with:
node-version: ${{ matrix.node_version }}
- uses: actions/setup-node@v3
name: Setup Node.JS
with:
node-version: ${{ matrix.node_version }}

- name: Run WASM tests
run: |
cargo install wasm-pack --force
cargo clean
npm install -g mocha
npm ci
npm test
- name: Run WASM tests
run: |
cargo install wasm-pack --force
cargo clean
npm install -g mocha
npm ci
npm test
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ serde = { version = "1.0", features = ["derive"] }
serde-wasm-bindgen = "0.6"
sourcemap = "6.4.1"
swc_atoms = "0.6.0"
swc_cached = "0.3.18"
swc_common = { version = "0.33.0", features = ["anyhow", "sourcemap"] }
swc_ecma_ast = { version = "0.110.0", features = ["default", "serde"] }
swc_ecma_codegen = "0.146.1"
Expand Down
35 changes: 34 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
export * from './pkg/compiler';
export { compile, start, prepareStackTrace } from './pkg/compiler';

declare interface JsMethodParameter {
name?: String;
index: number;
hasDefault: boolean;
isObjectPattern: boolean;
isArrayPattern: boolean;
isRestElement: boolean;
}

declare interface JsMemberData {
memberIndex: number;
kind: 'method' | 'field' | 'accessor' | 'getter' | 'setter';
name: string | symbol;
static?: boolean;
private?: boolean;
access?: { get?: () => any; set?: (v: any) => void };
parameters?: JsMethodParameter[];
docblock?: String;
}

declare interface JsReflectionData {
fqcn: String;
className: String;
namespace?: String;
filename?: String;
members: JsMemberData[];
docblock?: String;
}

export function getReflectionData(
classIdOrValue: any,
): JsReflectionData | undefined;
68 changes: 52 additions & 16 deletions lib/reflection.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,73 @@ function docblockGetter(classId, memberIndex) {
*/
exports._ = function __jymfony_reflect(classId, memberIndex = undefined) {
return (value, context) => {
const c = reflectionDataMap.get(classId) || { members: [] };
const c = (() => {
const d = reflectionDataMap.get(classId);
if (d !== undefined) {
return d;
}

const data = getInternalReflectionData(classId);
if (data === void 0) {
return {
fqcn: context.name,
className: context.name,
members: [],
};
}

const c = { ...data };
c.members = [];

return c;
})();

if (context.kind === 'class') {
context.metadata[reflectionSymbol] = classId;
if (memberIndex !== void 0) {
c.members.push({
memberIndex,
kind: 'method',
name: 'constructor',
static: false,
private: false,
access: { get: () => value },
get docblock() {
return docblockGetter(classId, memberIndex);
},
get parameters() {
const data = getInternalReflectionData(classId);
if (data === void 0) {
return [];
}

const member = data.members[memberIndex];

return member.params.map((p) => ({ ...p }));
},
});
}

reflectionDataMap.set(classId, c);
return;
}

if (!context.name) {
return;
}

const data = getInternalReflectionData(classId);
if (data === void 0) {
return;
}

if (context.kind === 'method') {
const getter = (() => {
if (context.access) {
return context.access.get;
}

return () => value;
})();

if (
context.kind === 'method' ||
context.kind === 'getter' ||
context.kind === 'setter'
) {
c.members.push({
memberIndex,
kind: context.kind,
name: context.name,
static: context.static,
private: context.private,
access: { get: getter },
access: context.access,
get parameters() {
const data = getInternalReflectionData(classId);
if (data === void 0) {
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jymfony/compiler",
"version": "0.5.0-alpha.1",
"version": "0.5.0-alpha.2",
"type": "commonjs",
"author": "Alessandro Chitolina <[email protected]>",
"license": "MIT",
Expand All @@ -22,6 +22,8 @@
"files": [
"index.js",
"index.d.ts",
"lib/_apply_decs_2203_r.js",
"lib/reflection.js",
"pkg/compiler.js",
"pkg/compiler.d.ts",
"pkg/compiler_bg.wasm",
Expand Down
Loading

0 comments on commit 13548c3

Please sign in to comment.