Skip to content

Commit

Permalink
0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ityuany committed Apr 29, 2024
1 parent db10b6e commit 46fbf86
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
7 changes: 7 additions & 0 deletions __test__/fixtures/demo1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Button } from "shineout"

import { Table as TTable } from "shineout"

import es_default from "shineout"

import * as es_name_space from "shineout"
15 changes: 9 additions & 6 deletions __test__/index.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import test from 'ava'
import { performance } from 'perf_hooks';
import { inspectPackageUsage} from '../index.js'

import path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

test('xx', (t) => {

test('should to be array of len is 4', (t) => {
const start = performance.now()
const res = inspectPackageUsage("shineout","/Users/10015448/GitRepository/fsp-front");
console.log(res);
const res = inspectPackageUsage("shineout",path.join(__dirname,"fixtures"));
const end = performance.now()
console.log(`inspectPackageUsage cost ${end - start} ms`);
console.log("xx");

t.is(res.length, 4);
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"name": "@shined/package-exported-usage",
"version": "0.0.2",
"version": "0.0.3",
"main": "index.js",
"types": "index.d.ts",
"napi": {
"name": "package-exported-usage",
"triples": {
"additional": [
"aarch64-apple-darwin",
"aarch64-unknown-linux-gnu",
"aarch64-unknown-linux-musl",
"aarch64-pc-windows-msvc",
"i686-pc-windows-msvc",
"aarch64-unknown-linux-gnu",
"aarch64-unknown-linux-musl",
"armv7-unknown-linux-gnueabihf",
"armv7-unknown-linux-musleabihf",
"x86_64-unknown-linux-musl"
Expand Down
35 changes: 25 additions & 10 deletions src/vistor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,35 @@ pub struct ImportVisitor {
pub package_name: String,
}

static ES_DEFAULT: &str = "ES:DEFAULT";

static ES_NAMESPACE: &str = "ES:NAMESPACE";

impl Visit for ImportVisitor {
fn visit_import_decl(&mut self, n: &ImportDecl) {
if n.src.value == self.package_name {
for specifier in &n.specifiers {
match specifier {
ImportSpecifier::Named(named) => {
if n.src.value != self.package_name {
return;
}

for specifier in &n.specifiers {
match specifier {
ImportSpecifier::Named(named) => {
if let Some(swc_ecmascript::ast::ModuleExportName::Ident(dent)) = named.imported.as_ref()
{
self.imports.push(dent.sym.to_string());
} else if let Some(swc_ecmascript::ast::ModuleExportName::Str(dent)) =
named.imported.as_ref()
{
self.imports.push(dent.value.to_string());
} else {
self.imports.push(named.local.sym.to_string());
}
ImportSpecifier::Default(_) => {
self.imports.push("ES:DEFAULT".to_string());
}
ImportSpecifier::Namespace(_) => {
self.imports.push("ES:NAMESPACE".to_string());
}
}
ImportSpecifier::Default(_) => {
self.imports.push(ES_DEFAULT.to_string());
}
ImportSpecifier::Namespace(_) => {
self.imports.push(ES_NAMESPACE.to_string());
}
}
}
Expand Down

0 comments on commit 46fbf86

Please sign in to comment.