Socket
Socket
Sign inDemoInstall

cjs-es

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cjs-es - npm Package Compare versions

Comparing version 0.8.1 to 0.8.2

2

lib/analyzer.js

@@ -85,3 +85,3 @@ const {walk} = require("estree-walker");

const exported = getExportInfo(node);
if (!exported) {
if (!exported || context.scope.has(exported.leftMost.name)) {
return;

@@ -88,0 +88,0 @@ }

{
"name": "cjs-es",
"version": "0.8.1",
"version": "0.8.2",
"description": "Transform CommonJS module into ES module.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -280,38 +280,59 @@ cjs-es

### async transform(options?: object): TransformResult object
### transform
`options` has following members:
```js
async transform({
parse?: (code: String) => ESTree,
code: String,
ast?: ESTree,
sourceMap?: Boolean = false,
importStyle?: String | async (moduleId) => String,
exportStyle?: String | async () => String,
nested?: Boolean,
warn?: (message: String, pos: Number) => void
})
=> TransformResult
```
* `parse?`: `function`. A parser function which can parse JavaScript code into ESTree.
* `code`: `string`. The JavaScript source code.
* `ast?`: AST object. If set then ignore `options.parse`.
* `sourceMap?`: `boolean`. If true then generate the source map. Default: `false`
* `importStyle?`: `string` or `function -> string`. The result must be `"named"` or `"default"`. Default: `"named"`
* `parse` is a parser function which can parse JavaScript code into AST. The module will use this function to parse `code`. You don't have to provide the `parse` function if `ast` is set.
When the value is a function, it recieves one argument:
* `code` is the JavaScript source code.
- `moduleId`: `string`. The module ID of `require("module-id")`.
* `ast` - if you already have the AST of the code, you can set it as `ast` so the module don't have to parse the code again.
* `exportStyle?`: `string` or `function -> string`. The result must be `"named"` or `"default"`. Default: `"named"`
* `nested?`: `boolean`. If true then analyze the entire AST, otherwise only top-level nodes are visited. If there is no nested require/exports/dynamic import statements, it is safe to keep it off. Default: `false`.
* `warn?`: `function`. This function is called when the transformer emmits a warning. The arguments are:
* `sourceMap` - if `true` then generate the source map.
- `message`: `string`. Warning message.
- `pos`: `number`. The position of the current node.
If undefined, the transformer would use global `console.error`.
* `importStyle` and `exportStyle` are used to decide how to transform import/export statements. The value or the value returned by the function must be `"named"` or `"default"`. By default, the transformer always prefer to use named exports for import/export statements.
`options.importStyle` and `options.exportStyle` could be async, and the return value would be cached (for `importStyle`, the value is cached for each `moduleId`).
If `importStyle` is a function, it will only be called once for each `moduleId` if needed.
The result object has following members:
If `exportStyle` is a function, it will only be called once if needed.
* `code`: string. The result JavaScript code.
* `map?`: object. The source map object generated by [`magicString.generateMap`](https://github.com/Rich-Harris/magic-string#sgeneratemap-options-). If `isTouched` or `options.sourceMap` is false then the map is null.
* `isTouched`: boolean. If false then the code is not changed.
* `warn` - the transformer uses `warn` function to emit a warning. If `warn` is not set then the transformer will print the message to the console using `console.error`.
If an error is thrown during walking the AST, the error has a property `pos` which points to the index of the current node.
### TransformResult
```js
{
code: String,
isTouched: Boolean,
map: Object | null
}
```
* `code` - the result ES source code.
* `isTouched` - if `true` then the code is changed.
* `map` is the source map object generated by [`magicString.generateMap`](https://github.com/Rich-Harris/magic-string#sgeneratemap-options-). Only available if `isTouched` and the `sourceMap` option are both `true`.
Changelog
---------
* 0.8.2 (Jul 2, 2019)
- Fix: nested export assignment doesn't check if exports is shadowed.
* 0.8.1 (Jun 18, 2019)

@@ -318,0 +339,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