Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/react/transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["cdylib"]
convert_case = { workspace = true }
hex = { workspace = true }
indexmap = { workspace = true }
napi = { workspace = true }
napi = { workspace = true, features = ["serde-json"] }
napi-derive = { workspace = true }
once_cell = { workspace = true }
regex = { workspace = true }
Expand Down
34 changes: 34 additions & 0 deletions packages/react/transform/__test__/fixture.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,40 @@ describe('ui source map', () => {
});
});

describe('element template', () => {
it('should export compiled element templates when enabled', async () => {
const result = await transformReactLynx('const node = <view className="foo" />;', {
mode: 'test',
pluginName: '',
filename: 'test.js',
sourcemap: false,
cssScope: false,
snapshot: {
preserveJsx: false,
runtimePkg: '@lynx-js/react',
filename: 'test.js',
target: 'LEPUS',
enableElementTemplate: true,
},
jsx: true,
directiveDCE: false,
defineDCE: false,
shake: false,
compat: true,
worklet: false,
refresh: false,
});

expect(Array.isArray(result.elementTemplates)).toBe(true);
const template = result.elementTemplates?.[0];
expect(template?.templateId).toEqual(expect.any(String));
expect(template?.templateId.length).toBeGreaterThan(0);
expect(template?.compiledTemplate).toEqual(expect.any(Object));
expect(Array.isArray(template?.compiledTemplate)).toBe(false);
expect(template?.sourceFile).toEqual(expect.any(String));
});
});

describe('jsx', () => {
it('should allow JSXNamespace', async () => {
const result = await transformReactLynx('const jsx = <Foo main-thread:foo={foo} />', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ napi = ["dep:napi", "dep:napi-derive", "swc_plugins_shared/napi"]
[dependencies]
convert_case = { workspace = true }
hex = { workspace = true }
napi = { workspace = true, optional = true }
napi = { workspace = true, optional = true, features = ["serde-json"] }
napi-derive = { workspace = true, optional = true }
once_cell = { workspace = true }
regex = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["preserve_order"] }
sha-1 = { workspace = true }
swc_core = { workspace = true, features = ["ecma_parser", "ecma_utils", "ecma_quote", "ecma_visit", "testing_transform", "ecma_transforms_react"] }
swc_core = { workspace = true, features = ["base", "ecma_codegen", "ecma_parser", "ecma_minifier", "ecma_transforms_typescript", "ecma_utils", "ecma_quote", "ecma_transforms_react", "ecma_transforms_optimization", "__visit", "__testing_transform"] }
swc_plugins_shared = { path = "../swc_plugins_shared" }

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(swc_ast_unknown)'] }

[dev-dependencies]
insta = { version = "1.34", features = ["json"] }
Loading
Loading