You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

acorn-import-assertions

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

acorn-import-assertions

Support for import assertions in acorn


Version published
Weekly downloads
14M
decreased by-2.07%
Maintainers
1
Install size
25.1 kB
Created
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

Package last updated on 12 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc