Socket
Socket
Sign inDemoInstall

acorn-import-assertions

Package Overview
Dependencies
1
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Protect your apps from supply chain attacks

Install

acorn-import-assertions

Support for import assertions in acorn

    1.9.0latest
    GitHub
    npm

Version published
Maintainers
1
Weekly downloads
18,265,938
increased by4.66%

Weekly downloads

Package description

What is acorn-import-assertions?

The acorn-import-assertions package is a plugin for the Acorn JavaScript parser. It adds support for parsing import assertions, which are a stage 3 proposal for ECMAScript that allows developers to make assertions about the type of module they are importing. This is particularly useful for distinguishing between different types of modules, such as JSON modules, CSS modules, or other non-JavaScript content.

What are acorn-import-assertions's main functionalities?

Parsing import assertions

This feature allows the parsing of import statements with assertions. The code sample demonstrates how to extend the Acorn parser with the importAssertions plugin and parse a piece of code that includes an import statement with an assertion.

import assert from 'assert';
import { Parser } from 'acorn';
import importAssertions from 'acorn-import-assertions';

const code = "import json from './data.json' assert { type: 'json' };";
const ast = Parser.extend(importAssertions).parse(code, { sourceType: 'module' });
assert(ast.body[0].assertions[0].value.value === 'json');

Other packages similar to acorn-import-assertions

Readme

Source

Support for import assertions in acorn

Usage

This module provides a plugin that can be used to extend the Acorn Parser class:

const {Parser} = require('acorn');
const {importAssertions} = require('acorn-import-assertions');
Parser.extend(importAssertions).parse('...');

License

This plugin is released under an MIT License.

FAQs

Last updated on 12 May 2023

Did you know?

Socket installs a GitHub app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc