Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

parse-imports

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

parse-imports - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

150

package.json
{
"name": "parse-imports",
"version": "1.1.0",
"author": {
"name": "Tomer Aberbach",
"email": "tomeraberbach@gmail.com",
"url": "https://tomeraberba.ch"
},
"description": "A blazing fast ES module imports parser.",
"keywords": [
"esm",
"imports",
"module",
"parser",
"imports"
],
"homepage": "https://github.com/TomerAberbach/parse-imports",
"repository": "TomerAberbach/parse-imports",
"bugs": {
"url": "https://github.com/TomerAberbach/parse-imports/issues"
},
"license": "Apache 2.0",
"files": [
"src"
],
"type": "module",
"engines": {
"node": ">= 12.17"
},
"browserslist": [
"defaults",
"not IE 11",
"not op_mini all"
],
"exports": "./src/index.js",
"module": "./src/index.js",
"types": "./src/index.d.ts",
"prettier": "@tomer/prettier-config",
"eslintConfig": {
"extends": "@tomer"
},
"lint-staged": {
"*.js": [
"addlicense",
"run-s \"lint:prettier:base -- --write {@}\" --",
"run-s \"lint:eslint:base -- --fix {@}\" --"
],
"*.ts": [
"addlicense",
"run-s \"lint:prettier:base -- --write {@}\" --"
],
"*.{json,yml,md}": "run-s \"lint:prettier:base -- --write {@}\" --"
},
"tsd": {
"directory": "./test"
},
"commitlint": {
"extends": "@commitlint/config-conventional"
},
"simple-git-hooks": {
"pre-commit": "pnpx --no-install lint-staged",
"commit-msg": "pnpx --no-install commitlint -e"
},
"dependencies": {
"es-module-lexer": "0.4.1",
"slashes": "2.0.2"
},
"devDependencies": {
"@commitlint/cli": "12.1.4",
"@commitlint/config-conventional": "12.1.4",
"@tomer/eslint-config": "0.1.1",
"@tomer/prettier-config": "0.1.0",
"ava": "3.15.0",
"ava-fast-check": "4.0.2",
"c8": "7.7.2",
"eslint": "7.27.0",
"fast-check": "2.14.0",
"lint-staged": "11.0.0",
"npm-run-all": "4.1.5",
"prettier": "2.3.0",
"shift-codegen": "7.0.3",
"shift-fuzzer": "1.0.2",
"simple-git-hooks": "2.4.1",
"tsd": "0.15.1",
"typescript": "4.3.2"
},
"scripts": {
"license": "addlicense $(git diff --name-only HEAD)",
"lint:prettier:base": "prettier --loglevel silent --ignore-path .eslintignore",
"lint:prettier": "run-s \"lint:prettier:base -- --write .\"",
"lint:eslint:base": "eslint --cache --ext js --ignore-path .eslintignore",
"lint:eslint": "run-s \"lint:eslint:base -- --fix .\"",
"lint": "run-s lint:*",
"test:js": "ava",
"test:ts": "tsd",
"test": "run-s test:*",
"coverage": "c8 run-s test:js"
}
}
"name": "parse-imports",
"version": "1.1.1",
"author": {
"name": "Tomer Aberbach",
"email": "tomeraberbach@gmail.com",
"url": "https://tomeraberba.ch"
},
"description": "A blazing fast ES module imports parser.",
"keywords": [
"esm",
"imports",
"module",
"parser",
"imports"
],
"homepage": "https://github.com/TomerAberbach/parse-imports",
"repository": "TomerAberbach/parse-imports",
"bugs": {
"url": "https://github.com/TomerAberbach/parse-imports/issues"
},
"license": "Apache 2.0",
"files": [
"src"
],
"type": "module",
"engines": {
"node": ">= 12.17"
},
"exports": "./src/index.js",
"module": "./src/index.js",
"types": "./src/index.d.ts",
"prettier": "tomer/prettier-config",
"dependencies": {
"es-module-lexer": "^1.2.1",
"slashes": "^3.0.12"
},
"devDependencies": {
"@types/jest": "^29.5.1",
"@types/node": "^18.16.3",
"eslint": "^8.39.0",
"jest": "^29.5.0",
"prettier": "^2.8.8",
"tomer": "^2.0.0",
"typescript": "^5.0.4"
},
"scripts": {
"format": "tomer format",
"lint": "tomer lint",
"typecheck": "tomer typecheck",
"test": "tomer test"
}
}

@@ -12,5 +12,2 @@ <h1 align="center">

</a>
<a href="https://bundlephobia.com/result?p=parse-imports">
<img src="https://badgen.net/bundlephobia/minzip/parse-imports" alt="minzip size" />
</a>
</div>

@@ -198,2 +195,4 @@

<!-- eslint-skip -->
```ts

@@ -200,0 +199,0 @@ type ModuleSpecifierType =

@@ -42,3 +42,3 @@ /**

default?: string
named: Array<{ specifier: string; binding: string }>
named: { specifier: string; binding: string }[]
namespace?: string

@@ -50,5 +50,5 @@ }

code: string,
options?: Options
options?: Options,
) => Promise<Iterable<Import>>
export default parseImports

@@ -24,3 +24,3 @@ /**

code,
resolveFrom == null ? undefined : resolveFrom
resolveFrom == null ? undefined : resolveFrom,
)

@@ -34,4 +34,9 @@

s: moduleSpecifierStartIndex,
e: moduleSpecifierEndIndexExclusive
e: moduleSpecifierEndIndexExclusive,
} of imports) {
const isImportMeta = dynamicImportStartIndex === -2
if (isImportMeta) {
continue
}
const isDynamicImport = dynamicImportStartIndex > -1

@@ -45,9 +50,9 @@

const moduleSpecifierString = code.substring(
const moduleSpecifierString = code.slice(
moduleSpecifierStartIndex,
moduleSpecifierEndIndexExclusive
moduleSpecifierEndIndexExclusive,
)
const moduleSpecifier = parseModuleSpecifier(moduleSpecifierString, {
isDynamicImport,
resolveFrom
resolveFrom,
})

@@ -58,11 +63,11 @@

let importClauseString = code
.substring(
.slice(
statementStartIndex + `import`.length,
moduleSpecifierStartIndex
moduleSpecifierStartIndex,
)
.trim()
if (importClauseString.endsWith(`from`)) {
importClauseString = importClauseString.substring(
importClauseString = importClauseString.slice(
0,
importClauseString.length - `from`.length
Math.max(0, importClauseString.length - `from`.length),
)

@@ -74,19 +79,13 @@ }

yield {
...(isDynamicImport
? {
startIndex: dynamicImportStartIndex,
// Include the closing parenthesis
endIndex: moduleSpecifierEndIndexExclusive + 1
}
: {
startIndex: statementStartIndex,
endIndex: moduleSpecifierEndIndexExclusive
}),
startIndex: statementStartIndex,
// Include the closing parenthesis for dynamic import
endIndex: isDynamicImport
? moduleSpecifierEndIndexExclusive + 1
: moduleSpecifierEndIndexExclusive,
isDynamicImport,
moduleSpecifier,
importClause
importClause,
}
}
}
},
}

@@ -93,0 +92,0 @@ }

@@ -37,3 +37,3 @@ /**

importClauseString,
i
i,
))

@@ -51,3 +51,3 @@ namedImports.push(...newNamedImports)

namespace: namespaceImport,
named: namedImports
named: namedImports,
}

@@ -54,0 +54,0 @@ }

@@ -23,5 +23,5 @@ /**

return { defaultImport: importClauseString.substring(startIndex, i), i }
return { defaultImport: importClauseString.slice(startIndex, i), i }
}
export default parseDefaultImport

@@ -25,3 +25,3 @@ /**

const namedImports = importClauseString
.substring(startIndex, i++)
.slice(startIndex, i++)
.split(`,`)

@@ -34,3 +34,3 @@ .map(namedImport => {

specifier: components[0],
binding: components[components.length - 1]
binding: components[components.length - 1],
}

@@ -37,0 +37,0 @@ }

@@ -29,4 +29,4 @@ /**

return {
namespaceImport: importClauseString.substring(startIndex, i),
i
namespaceImport: importClauseString.slice(startIndex, i),
i,
}

@@ -33,0 +33,0 @@ }

@@ -18,3 +18,3 @@ /**

import assert from 'assert'
import { stripSlashes } from 'slashes'
import { removeSlashes } from 'slashes'
import isConstantStringLiteral from './is-constant-string-literal.js'

@@ -26,3 +26,3 @@ import parseType from './parse-type.js'

moduleSpecifierString,
{ isDynamicImport, resolveFrom }
{ isDynamicImport, resolveFrom },
) => {

@@ -35,5 +35,3 @@ assert(isDynamicImport || isConstantStringLiteral(moduleSpecifierString))

isConstant: true,
value: stripSlashes(
moduleSpecifierString.substring(1, moduleSpecifierString.length - 1)
)
value: removeSlashes(moduleSpecifierString.slice(1, -1)),
}

@@ -50,3 +48,3 @@ : { isConstant: false, value: undefined }

? resolve(resolveFrom, value)
: undefined
: undefined,
}

@@ -53,0 +51,0 @@ }

@@ -22,3 +22,3 @@ /**

stringLiteral.startsWith(quoteCandidate) &&
stringLiteral.endsWith(quoteCandidate)
stringLiteral.endsWith(quoteCandidate),
)

@@ -39,3 +39,3 @@

quote === `\`` &&
stringLiteral.substring(i, i + 2) === `\${` &&
stringLiteral.slice(i, i + 2) === `\${` &&
stringLiteral[i - 1] !== `\\`

@@ -42,0 +42,0 @@ ) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc