feat(es/ast): Support import attributes proposal (#7868)

**Related issue:**

 - Closes #7179
This commit is contained in:
Donny/강동윤 2023-08-28 09:29:45 +09:00 committed by GitHub
parent 5d25307a1a
commit 4d3fcb86e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
515 changed files with 12048 additions and 844 deletions

View File

@ -1110,7 +1110,7 @@ impl Compiler {
jsx: true,
decorators: true,
decorators_before_export: true,
import_assertions: true,
import_attributes: true,
..Default::default()
}),
IsModule::Bool(true),

View File

@ -84,7 +84,7 @@ where
specifiers: vec![specifier],
src: None,
type_only: false,
asserts: None,
with: None,
})),
));
}

View File

@ -768,7 +768,7 @@ where
specifiers: vec![specifier],
src: None,
type_only: false,
asserts: None,
with: None,
},
)));
}
@ -816,7 +816,7 @@ where
specifiers: vec![specifier],
src: None,
type_only: false,
asserts: None,
with: None,
},
)));
}
@ -883,7 +883,7 @@ where
.collect(),
src: None,
type_only: false,
asserts: None,
with: None,
}));
extra.push(export);
continue;
@ -925,7 +925,7 @@ where
specifiers: vec![specifier],
src: None,
type_only: false,
asserts: None,
with: None,
},
)));
}
@ -1140,7 +1140,7 @@ where
span: ns.span,
specifiers: vec![specifier],
src: None,
asserts: None,
with: None,
type_only: false,
}),
));

View File

@ -250,7 +250,7 @@ where
specifiers: vec![],
src: Box::new(src.clone()),
type_only: false,
asserts: None,
with: None,
};
if self.top_level {
@ -657,7 +657,7 @@ where
.collect(),
src: Box::new(src),
type_only: false,
asserts: None,
with: None,
};
// if self.top_level {

View File

@ -304,7 +304,7 @@ where
specifiers: vec![],
src: Box::new(src),
type_only: false,
asserts: None,
with: None,
},
true,
false,

View File

@ -84,7 +84,7 @@ pub struct ImportDecl {
pub type_only: bool,
#[cfg_attr(feature = "serde-impl", serde(default))]
pub asserts: Option<Box<ObjectLit>>,
pub with: Option<Box<ObjectLit>>,
}
impl Take for ImportDecl {
@ -94,7 +94,7 @@ impl Take for ImportDecl {
specifiers: Take::dummy(),
src: Take::dummy(),
type_only: Default::default(),
asserts: Take::dummy(),
with: Take::dummy(),
}
}
}
@ -113,7 +113,7 @@ pub struct ExportAll {
pub type_only: bool,
#[cfg_attr(feature = "serde-impl", serde(default))]
pub asserts: Option<Box<ObjectLit>>,
pub with: Option<Box<ObjectLit>>,
}
impl Take for ExportAll {
@ -122,7 +122,7 @@ impl Take for ExportAll {
span: DUMMY_SP,
src: Take::dummy(),
type_only: Default::default(),
asserts: Take::dummy(),
with: Take::dummy(),
}
}
}
@ -144,7 +144,7 @@ pub struct NamedExport {
pub type_only: bool,
#[cfg_attr(feature = "serde-impl", serde(default))]
pub asserts: Option<Box<ObjectLit>>,
pub with: Option<Box<ObjectLit>>,
}
impl Take for NamedExport {
@ -154,7 +154,7 @@ impl Take for NamedExport {
specifiers: Take::dummy(),
src: Take::dummy(),
type_only: Default::default(),
asserts: Take::dummy(),
with: Take::dummy(),
}
}
}

View File

@ -308,11 +308,11 @@ where
emit!(n.src);
if let Some(asserts) = &n.asserts {
if let Some(with) = &n.with {
formatting_space!();
keyword!("assert");
keyword!("with");
formatting_space!();
emit!(asserts);
emit!(with);
}
semi!();
@ -451,11 +451,11 @@ where
formatting_space!();
emit!(src);
if let Some(asserts) = &node.asserts {
if let Some(with) = &node.with {
formatting_space!();
keyword!("assert");
keyword!("with");
formatting_space!();
emit!(asserts);
emit!(with);
}
}
semi!();
@ -477,11 +477,11 @@ where
formatting_space!();
emit!(node.src);
if let Some(asserts) = &node.asserts {
if let Some(with) = &node.with {
formatting_space!();
keyword!("assert");
keyword!("with");
formatting_space!();
emit!(asserts);
emit!(with);
}
semi!();

View File

@ -1,13 +1,13 @@
import data from "./data.json" assert {
import data from "./data.json" with {
type: "json"
};
import "./data2.json" assert {
import "./data2.json" with {
type: "json"
};
export { default as data3 } from "./data3.json" assert {
export { default as data3 } from "./data3.json" with {
type: "json"
};
export * as data4 from "./data4.json" assert {
export * as data4 from "./data4.json" with {
type: "json"
};
console.log(data);

View File

@ -1 +1 @@
import data from"./data.json"assert{type:"json"};import"./data2.json"assert{type:"json"};export{default as data3}from"./data3.json"assert{type:"json"};export*as data4 from"./data4.json"assert{type:"json"};console.log(data);
import data from"./data.json"with{type:"json"};import"./data2.json"with{type:"json"};export{default as data3}from"./data3.json"with{type:"json"};export*as data4 from"./data4.json"with{type:"json"};console.log(data);

View File

@ -41,7 +41,7 @@ pub enum ImportAssertion {
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum ImportAssertions {
pub enum ImportAttributes {
/// There was no import assertions object literal.
None,
/// The set of assertion keys could not be statically analyzed.
@ -51,16 +51,16 @@ pub enum ImportAssertions {
Known(HashMap<String, ImportAssertion>),
}
impl Default for ImportAssertions {
impl Default for ImportAttributes {
fn default() -> Self {
ImportAssertions::None
ImportAttributes::None
}
}
impl ImportAssertions {
impl ImportAttributes {
pub fn get(&self, key: &str) -> Option<&String> {
match self {
ImportAssertions::Known(map) => match map.get(key) {
ImportAttributes::Known(map) => match map.get(key) {
Some(ImportAssertion::Known(value)) => Some(value),
_ => None,
},
@ -84,7 +84,7 @@ pub struct DependencyDescriptor {
/// The span of the specifier.
pub specifier_span: Span,
/// Import assertions for this dependency.
pub import_assertions: ImportAssertions,
pub import_attributes: ImportAttributes,
}
struct DependencyCollector<'a> {
@ -110,7 +110,7 @@ impl<'a> Visit for DependencyCollector<'a> {
} else {
DependencyKind::Import
};
let import_assertions = parse_import_assertions(node.asserts.as_deref());
let import_attributes = parse_import_attributes(node.with.as_deref());
self.items.push(DependencyDescriptor {
kind,
is_dynamic: false,
@ -118,7 +118,7 @@ impl<'a> Visit for DependencyCollector<'a> {
span: node.span,
specifier,
specifier_span: node.src.span,
import_assertions,
import_attributes,
});
}
@ -131,7 +131,7 @@ impl<'a> Visit for DependencyCollector<'a> {
} else {
DependencyKind::Export
};
let import_assertions = parse_import_assertions(node.asserts.as_deref());
let import_attributes = parse_import_attributes(node.with.as_deref());
self.items.push(DependencyDescriptor {
kind,
is_dynamic: false,
@ -139,7 +139,7 @@ impl<'a> Visit for DependencyCollector<'a> {
span: node.span,
specifier,
specifier_span: src.span,
import_assertions,
import_attributes,
});
}
}
@ -152,7 +152,7 @@ impl<'a> Visit for DependencyCollector<'a> {
} else {
DependencyKind::Export
};
let import_assertions = parse_import_assertions(node.asserts.as_deref());
let import_attributes = parse_import_attributes(node.with.as_deref());
self.items.push(DependencyDescriptor {
kind,
is_dynamic: false,
@ -160,7 +160,7 @@ impl<'a> Visit for DependencyCollector<'a> {
span: node.span,
specifier,
specifier_span: node.src.span,
import_assertions,
import_attributes,
});
}
@ -175,7 +175,7 @@ impl<'a> Visit for DependencyCollector<'a> {
span: node.span,
specifier,
specifier_span: node.arg.span,
import_assertions: Default::default(),
import_attributes: Default::default(),
});
}
@ -230,7 +230,7 @@ impl<'a> Visit for DependencyCollector<'a> {
span: node.span,
specifier,
specifier_span: str_.span,
import_assertions: dynamic_import_assertions,
import_attributes: dynamic_import_assertions,
});
}
}
@ -259,7 +259,7 @@ impl<'a> Visit for DependencyCollector<'a> {
span: node.span,
specifier,
specifier_span: expr.span,
import_assertions: Default::default(),
import_attributes: Default::default(),
});
}
}
@ -268,13 +268,13 @@ impl<'a> Visit for DependencyCollector<'a> {
/// Parses import assertions into a hashmap. According to proposal the values
/// can only be strings (https://github.com/tc39/proposal-import-assertions#should-more-than-just-strings-be-supported-as-attribute-values)
/// and thus non-string values are skipped.
fn parse_import_assertions(asserts: Option<&ast::ObjectLit>) -> ImportAssertions {
let asserts = match asserts {
Some(asserts) => asserts,
None => return ImportAssertions::None,
fn parse_import_attributes(attrs: Option<&ast::ObjectLit>) -> ImportAttributes {
let attrs = match attrs {
Some(with) => with,
None => return ImportAttributes::None,
};
let mut import_assertions = HashMap::new();
for prop in asserts.props.iter() {
for prop in attrs.props.iter() {
if let ast::PropOrSpread::Prop(prop) = prop {
if let ast::Prop::KeyValue(key_value) = &**prop {
let maybe_key = match &key_value.key {
@ -292,23 +292,23 @@ fn parse_import_assertions(asserts: Option<&ast::ObjectLit>) -> ImportAssertions
}
}
}
ImportAssertions::Known(import_assertions)
ImportAttributes::Known(import_assertions)
}
/// Parses import assertions from the second arg of a dynamic import.
fn parse_dynamic_import_assertions(arg: Option<&ast::ExprOrSpread>) -> ImportAssertions {
fn parse_dynamic_import_assertions(arg: Option<&ast::ExprOrSpread>) -> ImportAttributes {
let arg = match arg {
Some(arg) => arg,
None => return ImportAssertions::None,
None => return ImportAttributes::None,
};
if arg.spread.is_some() {
return ImportAssertions::Unknown;
return ImportAttributes::Unknown;
}
let object_lit = match &*arg.expr {
ast::Expr::Object(object_lit) => object_lit,
_ => return ImportAssertions::Unknown,
_ => return ImportAttributes::Unknown,
};
let mut assertions_map = HashMap::new();
@ -317,37 +317,37 @@ fn parse_dynamic_import_assertions(arg: Option<&ast::ExprOrSpread>) -> ImportAss
for prop in object_lit.props.iter() {
let prop = match prop {
ast::PropOrSpread::Prop(prop) => prop,
_ => return ImportAssertions::Unknown,
_ => return ImportAttributes::Unknown,
};
let key_value = match &**prop {
ast::Prop::KeyValue(key_value) => key_value,
_ => return ImportAssertions::Unknown,
_ => return ImportAttributes::Unknown,
};
let key = match &key_value.key {
ast::PropName::Str(key) => key.value.to_string(),
ast::PropName::Ident(ident) => ident.sym.to_string(),
_ => return ImportAssertions::Unknown,
_ => return ImportAttributes::Unknown,
};
if key == "assert" {
if key == "assert" || key == "with" {
had_assert_key = true;
let assertions_lit = match &*key_value.value {
ast::Expr::Object(assertions_lit) => assertions_lit,
_ => return ImportAssertions::Unknown,
_ => return ImportAttributes::Unknown,
};
for prop in assertions_lit.props.iter() {
let prop = match prop {
ast::PropOrSpread::Prop(prop) => prop,
_ => return ImportAssertions::Unknown,
_ => return ImportAttributes::Unknown,
};
let key_value = match &**prop {
ast::Prop::KeyValue(key_value) => key_value,
_ => return ImportAssertions::Unknown,
_ => return ImportAttributes::Unknown,
};
let key = match &key_value.key {
ast::PropName::Str(key) => key.value.to_string(),
ast::PropName::Ident(ident) => ident.sym.to_string(),
_ => return ImportAssertions::Unknown,
_ => return ImportAttributes::Unknown,
};
if let ast::Expr::Lit(value_lit) = &*key_value.value {
assertions_map.insert(
@ -366,9 +366,9 @@ fn parse_dynamic_import_assertions(arg: Option<&ast::ExprOrSpread>) -> ImportAss
}
if had_assert_key {
ImportAssertions::Known(assertions_map)
ImportAttributes::Known(assertions_map)
} else {
ImportAssertions::None
ImportAttributes::None
}
}
@ -477,7 +477,7 @@ try {
span: Span::new(BytePos(1), BytePos(34), Default::default()),
specifier: JsWord::from("./test.ts"),
specifier_span: Span::new(BytePos(22), BytePos(33), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::ImportType,
@ -490,7 +490,7 @@ try {
span: Span::new(BytePos(48), BytePos(86), Default::default()),
specifier: JsWord::from("./foo.d.ts"),
specifier_span: Span::new(BytePos(73), BytePos(85), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::Export,
@ -503,7 +503,7 @@ try {
span: Span::new(BytePos(115), BytePos(149), Default::default()),
specifier: JsWord::from("./buzz.ts"),
specifier_span: Span::new(BytePos(137), BytePos(148), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::ExportType,
@ -523,7 +523,7 @@ try {
span: Span::new(BytePos(181), BytePos(221), Default::default()),
specifier: JsWord::from("./fizz.d.ts"),
specifier_span: Span::new(BytePos(207), BytePos(220), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::Require,
@ -532,7 +532,7 @@ try {
span: Span::new(BytePos(239), BytePos(254), Default::default()),
specifier: JsWord::from("path"),
specifier_span: Span::new(BytePos(247), BytePos(253), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -541,7 +541,7 @@ try {
span: Span::new(BytePos(274), BytePos(293), Default::default()),
specifier: JsWord::from("./foo1.ts"),
specifier_span: Span::new(BytePos(281), BytePos(292), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -550,7 +550,7 @@ try {
span: Span::new(BytePos(324), BytePos(342), Default::default()),
specifier: JsWord::from("./foo.ts"),
specifier_span: Span::new(BytePos(331), BytePos(341), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::Require,
@ -559,7 +559,7 @@ try {
span: Span::new(BytePos(395), BytePos(418), Default::default()),
specifier: JsWord::from("some_package"),
specifier_span: Span::new(BytePos(403), BytePos(417), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::ImportEquals,
@ -568,7 +568,7 @@ try {
span: Span::new(BytePos(449), BytePos(491), Default::default()),
specifier: JsWord::from("some_package_foo"),
specifier_span: Span::new(BytePos(471), BytePos(489), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::ImportType,
@ -577,7 +577,7 @@ try {
span: Span::new(BytePos(492), BytePos(547), Default::default()),
specifier: JsWord::from("some_package_foo_type"),
specifier_span: Span::new(BytePos(522), BytePos(545), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::ExportEquals,
@ -586,7 +586,7 @@ try {
span: Span::new(BytePos(548), BytePos(597), Default::default()),
specifier: JsWord::from("some_package_bar"),
specifier_span: Span::new(BytePos(577), BytePos(595), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::Require,
@ -595,7 +595,7 @@ try {
span: Span::new(BytePos(612), BytePos(651), Default::default()),
specifier: JsWord::from("some_package_resolve"),
specifier_span: Span::new(BytePos(628), BytePos(650), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::Require,
@ -604,7 +604,7 @@ try {
span: Span::new(BytePos(676), BytePos(719), Default::default()),
specifier: JsWord::from("some_package_resolve_foo"),
specifier_span: Span::new(BytePos(692), BytePos(718), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
]
);
@ -630,7 +630,7 @@ const d9 = await import("./d9.json", { assert: { type: "json", ...bar } });
const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad" } });
"#;
let (module, comments) = helper("test.ts", source).unwrap();
let expected_assertions1 = ImportAssertions::Known({
let expected_assertions1 = ImportAttributes::Known({
let mut map = HashMap::new();
map.insert(
"type".to_string(),
@ -638,7 +638,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
);
map
});
let expected_assertions2 = ImportAssertions::Known({
let expected_assertions2 = ImportAttributes::Known({
let mut map = HashMap::new();
map.insert(
"type".to_string(),
@ -646,7 +646,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
);
map
});
let dynamic_expected_assertions2 = ImportAssertions::Known({
let dynamic_expected_assertions2 = ImportAttributes::Known({
let mut map = HashMap::new();
map.insert(
"type".to_string(),
@ -666,7 +666,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(1), BytePos(66), Default::default()),
specifier: JsWord::from("./test.ts"),
specifier_span: Span::new(BytePos(22), BytePos(33), Default::default()),
import_assertions: expected_assertions1.clone(),
import_attributes: expected_assertions1.clone(),
},
DependencyDescriptor {
kind: DependencyKind::Export,
@ -675,7 +675,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(67), BytePos(125), Default::default()),
specifier: JsWord::from("./test.ts"),
specifier_span: Span::new(BytePos(81), BytePos(92), Default::default()),
import_assertions: expected_assertions1,
import_attributes: expected_assertions1,
},
DependencyDescriptor {
kind: DependencyKind::Export,
@ -684,7 +684,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(126), BytePos(186), Default::default()),
specifier: JsWord::from("./test.json"),
specifier_span: Span::new(BytePos(146), BytePos(159), Default::default()),
import_assertions: expected_assertions2.clone(),
import_attributes: expected_assertions2.clone(),
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -693,7 +693,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(187), BytePos(240), Default::default()),
specifier: JsWord::from("./foo.json"),
specifier_span: Span::new(BytePos(203), BytePos(215), Default::default()),
import_assertions: expected_assertions2,
import_attributes: expected_assertions2,
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -702,7 +702,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(260), BytePos(313), Default::default()),
specifier: JsWord::from("./fizz.json"),
specifier_span: Span::new(BytePos(267), BytePos(280), Default::default()),
import_assertions: dynamic_expected_assertions2.clone(),
import_attributes: dynamic_expected_assertions2.clone(),
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -711,7 +711,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(334), BytePos(387), Default::default()),
specifier: JsWord::from("./buzz.json"),
specifier_span: Span::new(BytePos(341), BytePos(354), Default::default()),
import_assertions: dynamic_expected_assertions2,
import_attributes: dynamic_expected_assertions2,
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -720,7 +720,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(406), BytePos(425), Default::default()),
specifier: JsWord::from("./d1.json"),
specifier_span: Span::new(BytePos(413), BytePos(424), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -729,7 +729,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(444), BytePos(467), Default::default()),
specifier: JsWord::from("./d2.json"),
specifier_span: Span::new(BytePos(451), BytePos(462), Default::default()),
import_assertions: Default::default(),
import_attributes: Default::default(),
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -738,7 +738,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(486), BytePos(510), Default::default()),
specifier: JsWord::from("./d3.json"),
specifier_span: Span::new(BytePos(493), BytePos(504), Default::default()),
import_assertions: ImportAssertions::Unknown,
import_attributes: ImportAttributes::Unknown,
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -747,7 +747,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(529), BytePos(564), Default::default()),
specifier: JsWord::from("./d4.json"),
specifier_span: Span::new(BytePos(536), BytePos(547), Default::default()),
import_assertions: ImportAssertions::Known(HashMap::new()),
import_attributes: ImportAttributes::Known(HashMap::new()),
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -756,7 +756,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(583), BytePos(619), Default::default()),
specifier: JsWord::from("./d5.json"),
specifier_span: Span::new(BytePos(590), BytePos(601), Default::default()),
import_assertions: ImportAssertions::Unknown,
import_attributes: ImportAttributes::Unknown,
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -765,7 +765,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(638), BytePos(681), Default::default()),
specifier: JsWord::from("./d6.json"),
specifier_span: Span::new(BytePos(645), BytePos(656), Default::default()),
import_assertions: ImportAssertions::Unknown,
import_attributes: ImportAttributes::Unknown,
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -774,7 +774,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(700), BytePos(754), Default::default()),
specifier: JsWord::from("./d7.json"),
specifier_span: Span::new(BytePos(707), BytePos(718), Default::default()),
import_assertions: ImportAssertions::Unknown,
import_attributes: ImportAttributes::Unknown,
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -783,7 +783,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(773), BytePos(819), Default::default()),
specifier: JsWord::from("./d8.json"),
specifier_span: Span::new(BytePos(780), BytePos(791), Default::default()),
import_assertions: ImportAssertions::Known({
import_attributes: ImportAttributes::Known({
let mut map = HashMap::new();
map.insert("type".to_string(), ImportAssertion::Unknown);
map
@ -796,7 +796,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(838), BytePos(895), Default::default()),
specifier: JsWord::from("./d9.json"),
specifier_span: Span::new(BytePos(845), BytePos(856), Default::default()),
import_assertions: ImportAssertions::Unknown,
import_attributes: ImportAttributes::Unknown,
},
DependencyDescriptor {
kind: DependencyKind::Import,
@ -805,7 +805,7 @@ const d10 = await import("./d10.json", { assert: { type: "json", ["type"]: "bad"
span: Span::new(BytePos(915), BytePos(982), Default::default()),
specifier: JsWord::from("./d10.json"),
specifier_span: Span::new(BytePos(922), BytePos(934), Default::default()),
import_assertions: ImportAssertions::Unknown,
import_attributes: ImportAttributes::Unknown,
},
]
);

View File

@ -48,7 +48,7 @@ impl VisitMut for Merger {
specifiers: self.specifiers.take(),
span: DUMMY_SP,
type_only: Default::default(),
asserts: Default::default(),
with: Default::default(),
},
)));
}
@ -61,7 +61,7 @@ impl VisitMut for Merger {
specifiers: Default::default(),
span: DUMMY_SP,
type_only: Default::default(),
asserts: Default::default(),
with: Default::default(),
},
)));
}

View File

@ -175,11 +175,11 @@ impl Syntax {
}
}
pub fn import_assertions(self) -> bool {
pub fn import_attributes(self) -> bool {
match self {
Syntax::Es(EsConfig {
import_assertions, ..
}) => import_assertions,
import_attributes, ..
}) => import_attributes,
Syntax::Typescript(_) => true,
}
}
@ -284,7 +284,10 @@ impl Syntax {
pub fn explicit_resource_management(&self) -> bool {
match self {
Syntax::Es(EsConfig { using_decl, .. }) => *using_decl,
Syntax::Es(EsConfig {
explicit_resource_management: using_decl,
..
}) => *using_decl,
Syntax::Typescript(_) => true,
}
}
@ -341,8 +344,8 @@ pub struct EsConfig {
pub export_default_from: bool,
/// Stage 3.
#[serde(default)]
pub import_assertions: bool,
#[serde(default, alias = "importAssertions")]
pub import_attributes: bool,
#[serde(default, rename = "allowSuperOutsideMethod")]
pub allow_super_outside_method: bool,
@ -354,7 +357,7 @@ pub struct EsConfig {
pub auto_accessors: bool,
#[serde(default)]
pub using_decl: bool,
pub explicit_resource_management: bool,
}
/// Syntactic context.

View File

@ -740,7 +740,7 @@ impl<I: Tokens> Parser<I> {
expect!(p, ',');
// Handle trailing comma.
if is!(p, ')') {
if is_dynamic_import && !p.input.syntax().import_assertions() {
if is_dynamic_import && !p.input.syntax().import_attributes() {
syntax_error!(
p,
span!(p, start),

View File

@ -2434,7 +2434,7 @@ export default function waitUntil(callback, options = {}) {
test_parser(
src,
Syntax::Es(EsConfig {
import_assertions: true,
import_attributes: true,
..Default::default()
}),
|p| p.parse_expr(),

View File

@ -63,9 +63,9 @@ impl<I: Tokens> Parser<I> {
_ => unreachable!(),
};
let _ = cur!(self, false);
let asserts = if self.input.syntax().import_assertions()
let with = if self.input.syntax().import_attributes()
&& !self.input.had_line_break_before_cur()
&& eat!(self, "assert")
&& (eat!(self, "assert") || eat!(self, "with"))
{
match *self.parse_object::<Box<Expr>>()? {
Expr::Object(v) => Some(Box::new(v)),
@ -80,7 +80,7 @@ impl<I: Tokens> Parser<I> {
src,
specifiers: vec![],
type_only: false,
asserts,
with,
}))
.map(ModuleItem::from);
}
@ -157,9 +157,9 @@ impl<I: Tokens> Parser<I> {
};
let _ = cur!(self, false);
let asserts = if self.input.syntax().import_assertions()
let with = if self.input.syntax().import_attributes()
&& !self.input.had_line_break_before_cur()
&& eat!(self, "assert")
&& (eat!(self, "assert") || eat!(self, "with"))
{
match *self.parse_object::<Box<Expr>>()? {
Expr::Object(v) => Some(Box::new(v)),
@ -176,7 +176,7 @@ impl<I: Tokens> Parser<I> {
specifiers,
src,
type_only,
asserts,
with,
}))
.map(ModuleItem::from)
}
@ -570,12 +570,12 @@ impl<I: Tokens> Parser<I> {
assert_and_bump!(self, '*');
// improve error message for `export * from foo`
let (src, asserts) = self.parse_from_clause_and_semi()?;
let (src, with) = self.parse_from_clause_and_semi()?;
return Ok(ModuleDecl::ExportAll(ExportAll {
span: span!(self, start),
src,
type_only,
asserts,
with,
}));
}
@ -617,13 +617,13 @@ impl<I: Tokens> Parser<I> {
if has_default || has_ns {
if is!(self, "from") {
let (src, asserts) = self.parse_from_clause_and_semi()?;
let (src, with) = self.parse_from_clause_and_semi()?;
return Ok(ModuleDecl::ExportNamed(NamedExport {
span: span!(self, start),
specifiers,
src: Some(src),
type_only,
asserts,
with,
}));
} else if !self.input.syntax().export_default_from() {
// emit error
@ -667,7 +667,7 @@ impl<I: Tokens> Parser<I> {
}
None
};
let (src, asserts) = match opt {
let (src, with) = match opt {
Some(v) => (Some(v.0), v.1),
None => (None, None),
};
@ -676,7 +676,7 @@ impl<I: Tokens> Parser<I> {
specifiers,
src,
type_only,
asserts,
with,
}));
};
@ -793,7 +793,7 @@ impl<I: Tokens> Parser<I> {
})
}
/// Parses `from 'foo.js' assert {};`
/// Parses `from 'foo.js' with {};` or `from 'foo.js' assert {};`
fn parse_from_clause_and_semi(&mut self) -> PResult<(Box<Str>, Option<Box<ObjectLit>>)> {
expect!(self, "from");
@ -810,9 +810,9 @@ impl<I: Tokens> Parser<I> {
_ => unexpected!(self, "a string literal"),
};
let _ = cur!(self, false);
let asserts = if self.input.syntax().import_assertions()
let with = if self.input.syntax().import_attributes()
&& !self.input.had_line_break_before_cur()
&& eat!(self, "assert")
&& (eat!(self, "assert") || eat!(self, "with"))
{
match *self.parse_object::<Box<Expr>>()? {
Expr::Object(v) => Some(Box::new(v)),
@ -822,7 +822,7 @@ impl<I: Tokens> Parser<I> {
None
};
expect!(self, ';');
Ok((src, asserts))
Ok((src, with))
}
}

View File

@ -29,7 +29,7 @@ fn test(input: PathBuf) {
decorators: true,
decorators_before_export: false,
export_default_from: true,
import_assertions: true,
import_attributes: true,
..Default::default()
}),
"ts" | "tsx" => Syntax::Typescript(TsConfig {

View File

@ -47,7 +47,7 @@ where
} else {
::swc_ecma_parser::Syntax::Es(::swc_ecma_parser::EsConfig {
jsx: is_jsx,
using_decl: true,
explicit_resource_management: true,
..Default::default()
})
};

View File

@ -91,7 +91,8 @@ where
let lexer = Lexer::new(
Syntax::Es(EsConfig {
using_decl: true,
explicit_resource_management: true,
import_attributes: true,
..Default::default()
}),
EsVersion::Es2015,

View File

@ -0,0 +1 @@
import("foo.json", { with: { type: "json" } })

View File

@ -0,0 +1,110 @@
{
"type": "Script",
"span": {
"start": 1,
"end": 47,
"ctxt": 0
},
"body": [
{
"type": "ExpressionStatement",
"span": {
"start": 1,
"end": 47,
"ctxt": 0
},
"expression": {
"type": "CallExpression",
"span": {
"start": 1,
"end": 47,
"ctxt": 0
},
"callee": {
"type": "Import",
"span": {
"start": 1,
"end": 7,
"ctxt": 0
}
},
"arguments": [
{
"spread": null,
"expression": {
"type": "StringLiteral",
"span": {
"start": 8,
"end": 18,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
}
},
{
"spread": null,
"expression": {
"type": "ObjectExpression",
"span": {
"start": 20,
"end": 46,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 22,
"end": 26,
"ctxt": 0
},
"value": "with",
"optional": false
},
"value": {
"type": "ObjectExpression",
"span": {
"start": 28,
"end": 44,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 30,
"end": 34,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 36,
"end": 42,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
]
}
}
],
"typeArguments": null
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,8 @@
{
"plugins": [
[
"importAssertions"
]
],
"sourceType": "module"
}

View File

@ -0,0 +1,2 @@
import foo from "foo.json" with { for: "for" }
export { foo } from "foo.json" with { for: "for" }

View File

@ -0,0 +1,157 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 98,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 47,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "foo",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 17,
"end": 27,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 33,
"end": 47,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 35,
"end": 38,
"ctxt": 0
},
"value": "for",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 40,
"end": 45,
"ctxt": 0
},
"value": "for",
"raw": "\"for\""
}
}
]
}
},
{
"type": "ExportNamedDeclaration",
"span": {
"start": 48,
"end": 98,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 57,
"end": 60,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 57,
"end": 60,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"exported": null,
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 68,
"end": 78,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 84,
"end": 98,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 86,
"end": 89,
"ctxt": 0
},
"value": "for",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 91,
"end": 96,
"ctxt": 0
},
"value": "for",
"raw": "\"for\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,2 @@
import("foo.js",);
import("foo.json", { with: { type: "json" } },);

View File

@ -0,0 +1,150 @@
{
"type": "Script",
"span": {
"start": 1,
"end": 68,
"ctxt": 0
},
"body": [
{
"type": "ExpressionStatement",
"span": {
"start": 1,
"end": 19,
"ctxt": 0
},
"expression": {
"type": "CallExpression",
"span": {
"start": 1,
"end": 18,
"ctxt": 0
},
"callee": {
"type": "Import",
"span": {
"start": 1,
"end": 7,
"ctxt": 0
}
},
"arguments": [
{
"spread": null,
"expression": {
"type": "StringLiteral",
"span": {
"start": 8,
"end": 16,
"ctxt": 0
},
"value": "foo.js",
"raw": "\"foo.js\""
}
}
],
"typeArguments": null
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 20,
"end": 68,
"ctxt": 0
},
"expression": {
"type": "CallExpression",
"span": {
"start": 20,
"end": 67,
"ctxt": 0
},
"callee": {
"type": "Import",
"span": {
"start": 20,
"end": 26,
"ctxt": 0
}
},
"arguments": [
{
"spread": null,
"expression": {
"type": "StringLiteral",
"span": {
"start": 27,
"end": 37,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
}
},
{
"spread": null,
"expression": {
"type": "ObjectExpression",
"span": {
"start": 39,
"end": 65,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 41,
"end": 45,
"ctxt": 0
},
"value": "with",
"optional": false
},
"value": {
"type": "ObjectExpression",
"span": {
"start": 47,
"end": 63,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 49,
"end": 53,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 55,
"end": 61,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
]
}
}
],
"typeArguments": null
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,2 @@
import foo from "foo" with { type: "json", }
export { default as foo } from "foo" with { type: "json", }

View File

@ -0,0 +1,166 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 105,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 45,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "foo",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 17,
"end": 22,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 28,
"end": 45,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 30,
"end": 34,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 36,
"end": 42,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
},
{
"type": "ExportNamedDeclaration",
"span": {
"start": 46,
"end": 105,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 55,
"end": 69,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 55,
"end": 62,
"ctxt": 0
},
"value": "default",
"optional": false
},
"exported": {
"type": "Identifier",
"span": {
"start": 66,
"end": 69,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 77,
"end": 82,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 88,
"end": 105,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 90,
"end": 94,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 96,
"end": 102,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,4 @@
import foo, { bar } from "foo" with {};
import * as ns from "foo" with {};
export { quux } from "foo" with {};
export * as ns2 from "foo" with {};

View File

@ -0,0 +1,225 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 147,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 40,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "foo",
"optional": false
}
},
{
"type": "ImportSpecifier",
"span": {
"start": 15,
"end": 18,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 15,
"end": 18,
"ctxt": 0
},
"value": "bar",
"optional": false
},
"imported": null,
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 26,
"end": 31,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 37,
"end": 39,
"ctxt": 0
},
"properties": []
}
},
{
"type": "ImportDeclaration",
"span": {
"start": 41,
"end": 75,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportNamespaceSpecifier",
"span": {
"start": 48,
"end": 55,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 53,
"end": 55,
"ctxt": 0
},
"value": "ns",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 61,
"end": 66,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 72,
"end": 74,
"ctxt": 0
},
"properties": []
}
},
{
"type": "ExportNamedDeclaration",
"span": {
"start": 76,
"end": 111,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 85,
"end": 89,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 85,
"end": 89,
"ctxt": 0
},
"value": "quux",
"optional": false
},
"exported": null,
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 97,
"end": 102,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 108,
"end": 110,
"ctxt": 0
},
"properties": []
}
},
{
"type": "ExportNamedDeclaration",
"span": {
"start": 112,
"end": 147,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportNamespaceSpecifier",
"span": {
"start": 119,
"end": 127,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 124,
"end": 127,
"ctxt": 0
},
"value": "ns2",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 133,
"end": 138,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 144,
"end": 146,
"ctxt": 0
},
"properties": []
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
export class Foo {}

View File

@ -0,0 +1,45 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 20,
"ctxt": 0
},
"body": [
{
"type": "ExportDeclaration",
"span": {
"start": 1,
"end": 20,
"ctxt": 0
},
"declaration": {
"type": "ClassDeclaration",
"identifier": {
"type": "Identifier",
"span": {
"start": 14,
"end": 17,
"ctxt": 0
},
"value": "Foo",
"optional": false
},
"declare": false,
"span": {
"start": 8,
"end": 20,
"ctxt": 0
},
"decorators": [],
"body": [],
"superClass": null,
"isAbstract": false,
"typeParams": null,
"superTypeParams": null,
"implements": []
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
export function foo() {}

View File

@ -0,0 +1,53 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 25,
"ctxt": 0
},
"body": [
{
"type": "ExportDeclaration",
"span": {
"start": 1,
"end": 25,
"ctxt": 0
},
"declaration": {
"type": "FunctionDeclaration",
"identifier": {
"type": "Identifier",
"span": {
"start": 17,
"end": 20,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"declare": false,
"params": [],
"decorators": [],
"span": {
"start": 8,
"end": 25,
"ctxt": 0
},
"body": {
"type": "BlockStatement",
"span": {
"start": 23,
"end": 25,
"ctxt": 0
},
"stmts": []
},
"generator": false,
"async": false,
"typeParameters": null,
"returnType": null
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
export const foo = "";

View File

@ -0,0 +1,61 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 23,
"ctxt": 0
},
"body": [
{
"type": "ExportDeclaration",
"span": {
"start": 1,
"end": 23,
"ctxt": 0
},
"declaration": {
"type": "VariableDeclaration",
"span": {
"start": 8,
"end": 23,
"ctxt": 0
},
"kind": "const",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 14,
"end": 22,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 14,
"end": 17,
"ctxt": 0
},
"value": "foo",
"optional": false,
"typeAnnotation": null
},
"init": {
"type": "StringLiteral",
"span": {
"start": 20,
"end": 22,
"ctxt": 0
},
"value": "",
"raw": "\"\""
},
"definite": false
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,3 @@
const foo = "";
export { foo };

View File

@ -0,0 +1,86 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 33,
"ctxt": 0
},
"body": [
{
"type": "VariableDeclaration",
"span": {
"start": 1,
"end": 16,
"ctxt": 0
},
"kind": "const",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 7,
"end": 15,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 7,
"end": 10,
"ctxt": 0
},
"value": "foo",
"optional": false,
"typeAnnotation": null
},
"init": {
"type": "StringLiteral",
"span": {
"start": 13,
"end": 15,
"ctxt": 0
},
"value": "",
"raw": "\"\""
},
"definite": false
}
]
},
{
"type": "ExportNamedDeclaration",
"span": {
"start": 18,
"end": 33,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 27,
"end": 30,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 27,
"end": 30,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"exported": null,
"isTypeOnly": false
}
],
"source": null,
"typeOnly": false,
"with": null
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
import "foo" with { "type": "json" };

View File

@ -0,0 +1,64 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 38,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 38,
"ctxt": 0
},
"specifiers": [],
"source": {
"type": "StringLiteral",
"span": {
"start": 8,
"end": 13,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 19,
"end": 37,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "StringLiteral",
"span": {
"start": 21,
"end": 27,
"ctxt": 0
},
"value": "type",
"raw": "\"type\""
},
"value": {
"type": "StringLiteral",
"span": {
"start": 29,
"end": 35,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
export * as foo from "foo.json" with { type: "json" };

View File

@ -0,0 +1,83 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 55,
"ctxt": 0
},
"body": [
{
"type": "ExportNamedDeclaration",
"span": {
"start": 1,
"end": 55,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportNamespaceSpecifier",
"span": {
"start": 8,
"end": 16,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 13,
"end": 16,
"ctxt": 0
},
"value": "foo",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 22,
"end": 32,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 38,
"end": 54,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 40,
"end": 44,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 46,
"end": 52,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
export * from "foo.json" with { type: "json" };

View File

@ -0,0 +1,63 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 48,
"ctxt": 0
},
"body": [
{
"type": "ExportAllDeclaration",
"span": {
"start": 1,
"end": 48,
"ctxt": 0
},
"source": {
"type": "StringLiteral",
"span": {
"start": 15,
"end": 25,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 31,
"end": 47,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 33,
"end": 37,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 39,
"end": 45,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,2 @@
export { default as x } from "foo" with
{ type: "json" }

View File

@ -0,0 +1,94 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 57,
"ctxt": 0
},
"body": [
{
"type": "ExportNamedDeclaration",
"span": {
"start": 1,
"end": 57,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 10,
"end": 22,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 10,
"end": 17,
"ctxt": 0
},
"value": "default",
"optional": false
},
"exported": {
"type": "Identifier",
"span": {
"start": 21,
"end": 22,
"ctxt": 0
},
"value": "x",
"optional": false
},
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 30,
"end": 35,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 41,
"end": 57,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 43,
"end": 47,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 49,
"end": 55,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,2 @@
export { "default" as x } from "foo" with { type: "json" }
[0]

View File

@ -0,0 +1,125 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 63,
"ctxt": 0
},
"body": [
{
"type": "ExportNamedDeclaration",
"span": {
"start": 1,
"end": 59,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 10,
"end": 24,
"ctxt": 0
},
"orig": {
"type": "StringLiteral",
"span": {
"start": 10,
"end": 19,
"ctxt": 0
},
"value": "default",
"raw": "\"default\""
},
"exported": {
"type": "Identifier",
"span": {
"start": 23,
"end": 24,
"ctxt": 0
},
"value": "x",
"optional": false
},
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 32,
"end": 37,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 43,
"end": 59,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 45,
"end": 49,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 51,
"end": 57,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 60,
"end": 63,
"ctxt": 0
},
"expression": {
"type": "ArrayExpression",
"span": {
"start": 60,
"end": 63,
"ctxt": 0
},
"elements": [
{
"spread": null,
"expression": {
"type": "NumericLiteral",
"span": {
"start": 61,
"end": 62,
"ctxt": 0
},
"value": 0.0,
"raw": "0"
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
export { default as foo } from "foo.json" with { type: "json" };

View File

@ -0,0 +1,94 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 65,
"ctxt": 0
},
"body": [
{
"type": "ExportNamedDeclaration",
"span": {
"start": 1,
"end": 65,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 10,
"end": 24,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 10,
"end": 17,
"ctxt": 0
},
"value": "default",
"optional": false
},
"exported": {
"type": "Identifier",
"span": {
"start": 21,
"end": 24,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 32,
"end": 42,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 48,
"end": 64,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 50,
"end": 54,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 56,
"end": 62,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
export { default } from "foo.json" with { type: "json", lazy: true, startAtLine: 1 };

View File

@ -0,0 +1,130 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 86,
"ctxt": 0
},
"body": [
{
"type": "ExportNamedDeclaration",
"span": {
"start": 1,
"end": 86,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 10,
"end": 17,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 10,
"end": 17,
"ctxt": 0
},
"value": "default",
"optional": false
},
"exported": null,
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 25,
"end": 35,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 41,
"end": 85,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 43,
"end": 47,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 49,
"end": 55,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
},
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 57,
"end": 61,
"ctxt": 0
},
"value": "lazy",
"optional": false
},
"value": {
"type": "BooleanLiteral",
"span": {
"start": 63,
"end": 67,
"ctxt": 0
},
"value": true
}
},
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 69,
"end": 80,
"ctxt": 0
},
"value": "startAtLine",
"optional": false
},
"value": {
"type": "NumericLiteral",
"span": {
"start": 82,
"end": 83,
"ctxt": 0
},
"value": 1.0,
"raw": "1"
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,3 @@
{
"throws": "Only string literals are allowed as module attribute values. (1:62)"
}

View File

@ -0,0 +1 @@
export { default } from "foo.json" with { lazy: "true" };

View File

@ -0,0 +1,85 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 58,
"ctxt": 0
},
"body": [
{
"type": "ExportNamedDeclaration",
"span": {
"start": 1,
"end": 58,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 10,
"end": 17,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 10,
"end": 17,
"ctxt": 0
},
"value": "default",
"optional": false
},
"exported": null,
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 25,
"end": 35,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 41,
"end": 57,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 43,
"end": 47,
"ctxt": 0
},
"value": "lazy",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 49,
"end": 55,
"ctxt": 0
},
"value": "true",
"raw": "\"true\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
export { default } from "foo.json" with { type: "json", hasOwnProperty: "true" };

View File

@ -0,0 +1,108 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 82,
"ctxt": 0
},
"body": [
{
"type": "ExportNamedDeclaration",
"span": {
"start": 1,
"end": 82,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 10,
"end": 17,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 10,
"end": 17,
"ctxt": 0
},
"value": "default",
"optional": false
},
"exported": null,
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 25,
"end": 35,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 41,
"end": 81,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 43,
"end": 47,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 49,
"end": 55,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
},
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 57,
"end": 71,
"ctxt": 0
},
"value": "hasOwnProperty",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 73,
"end": 79,
"ctxt": 0
},
"value": "true",
"raw": "\"true\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,53 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 32,
"ctxt": 0
},
"body": [
{
"type": "ExportNamedDeclaration",
"span": {
"start": 1,
"end": 32,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 10,
"end": 13,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 10,
"end": 13,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"exported": null,
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 21,
"end": 31,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": null
}
],
"interpreter": null
}

View File

@ -0,0 +1,2 @@
import "x" with { type: "json" }
[0]

View File

@ -0,0 +1,95 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 37,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 33,
"ctxt": 0
},
"specifiers": [],
"source": {
"type": "StringLiteral",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "x",
"raw": "\"x\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 17,
"end": 33,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 19,
"end": 23,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 25,
"end": 31,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 34,
"end": 37,
"ctxt": 0
},
"expression": {
"type": "ArrayExpression",
"span": {
"start": 34,
"end": 37,
"ctxt": 0
},
"elements": [
{
"spread": null,
"expression": {
"type": "NumericLiteral",
"span": {
"start": 35,
"end": 36,
"ctxt": 0
},
"value": 0.0,
"raw": "0"
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,64 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 33,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 33,
"ctxt": 0
},
"specifiers": [],
"source": {
"type": "StringLiteral",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "x",
"raw": "\"x\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 17,
"end": 33,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 19,
"end": 23,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 25,
"end": 31,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
import foo from "foo.json" with { type: "json" };

View File

@ -0,0 +1,83 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 50,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 50,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "foo",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 17,
"end": 27,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 33,
"end": 49,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 35,
"end": 39,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 41,
"end": 47,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
import foo from "foo.json" with { type: "json", lazy: true, startAtLine: 1 };

View File

@ -0,0 +1,128 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 78,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 78,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "foo",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 17,
"end": 27,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 33,
"end": 77,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 35,
"end": 39,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 41,
"end": 47,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
},
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 49,
"end": 53,
"ctxt": 0
},
"value": "lazy",
"optional": false
},
"value": {
"type": "BooleanLiteral",
"span": {
"start": 55,
"end": 59,
"ctxt": 0
},
"value": true
}
},
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 61,
"end": 72,
"ctxt": 0
},
"value": "startAtLine",
"optional": false
},
"value": {
"type": "NumericLiteral",
"span": {
"start": 74,
"end": 75,
"ctxt": 0
},
"value": 1.0,
"raw": "1"
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,3 @@
{
"throws": "Only string literals are allowed as module attribute values. (1:54)"
}

View File

@ -0,0 +1 @@
import foo from "foo.json" with { lazy: "true" };

View File

@ -0,0 +1,83 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 50,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 50,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "foo",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 17,
"end": 27,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 33,
"end": 49,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 35,
"end": 39,
"ctxt": 0
},
"value": "lazy",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 41,
"end": 47,
"ctxt": 0
},
"value": "true",
"raw": "\"true\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
import foo from "foo.json" with { type: "json", hasOwnProperty: "true" };

View File

@ -0,0 +1,106 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 74,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 74,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "foo",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 17,
"end": 27,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 33,
"end": 73,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 35,
"end": 39,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 41,
"end": 47,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
},
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 49,
"end": 63,
"ctxt": 0
},
"value": "hasOwnProperty",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 65,
"end": 71,
"ctxt": 0
},
"value": "true",
"raw": "\"true\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,51 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 28,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 28,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "foo",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 17,
"end": 27,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": null
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
import foo from "foo.json" with { type: "json" };

View File

@ -0,0 +1,83 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 50,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 50,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "foo",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 17,
"end": 27,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 33,
"end": 49,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 35,
"end": 39,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 41,
"end": 47,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,5 @@
{
"plugins": [],
"sourceType": "module",
"throws": "This experimental syntax requires enabling the parser plugin: \"importAttributes\". (1:32)"
}

View File

@ -0,0 +1 @@
import("foo.json", { assert: { type: "json" } })

View File

@ -0,0 +1,110 @@
{
"type": "Script",
"span": {
"start": 1,
"end": 49,
"ctxt": 0
},
"body": [
{
"type": "ExpressionStatement",
"span": {
"start": 1,
"end": 49,
"ctxt": 0
},
"expression": {
"type": "CallExpression",
"span": {
"start": 1,
"end": 49,
"ctxt": 0
},
"callee": {
"type": "Import",
"span": {
"start": 1,
"end": 7,
"ctxt": 0
}
},
"arguments": [
{
"spread": null,
"expression": {
"type": "StringLiteral",
"span": {
"start": 8,
"end": 18,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
}
},
{
"spread": null,
"expression": {
"type": "ObjectExpression",
"span": {
"start": 20,
"end": 48,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 22,
"end": 28,
"ctxt": 0
},
"value": "assert",
"optional": false
},
"value": {
"type": "ObjectExpression",
"span": {
"start": 30,
"end": 46,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 32,
"end": 36,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 38,
"end": 44,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
]
}
}
],
"typeArguments": null
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,2 @@
import "x"
assert ({});

View File

@ -0,0 +1,73 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 24,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 11,
"ctxt": 0
},
"specifiers": [],
"source": {
"type": "StringLiteral",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "x",
"raw": "\"x\""
},
"typeOnly": false,
"with": null
},
{
"type": "ExpressionStatement",
"span": {
"start": 12,
"end": 24,
"ctxt": 0
},
"expression": {
"type": "CallExpression",
"span": {
"start": 12,
"end": 23,
"ctxt": 0
},
"callee": {
"type": "Identifier",
"span": {
"start": 12,
"end": 18,
"ctxt": 0
},
"value": "assert",
"optional": false
},
"arguments": [
{
"spread": null,
"expression": {
"type": "ObjectExpression",
"span": {
"start": 20,
"end": 22,
"ctxt": 0
},
"properties": []
}
}
],
"typeArguments": null
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,4 @@
{
"plugins": ["importAssertions"],
"sourceType": "module"
}

View File

@ -0,0 +1,2 @@
import foo from "foo.json" assert { for: "for" }
export { foo } from "foo.json" assert { for: "for" }

View File

@ -0,0 +1,157 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 102,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 49,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "foo",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 17,
"end": 27,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 35,
"end": 49,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 37,
"end": 40,
"ctxt": 0
},
"value": "for",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 42,
"end": 47,
"ctxt": 0
},
"value": "for",
"raw": "\"for\""
}
}
]
}
},
{
"type": "ExportNamedDeclaration",
"span": {
"start": 50,
"end": 102,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 59,
"end": 62,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 59,
"end": 62,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"exported": null,
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 70,
"end": 80,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 88,
"end": 102,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 90,
"end": 93,
"ctxt": 0
},
"value": "for",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 95,
"end": 100,
"ctxt": 0
},
"value": "for",
"raw": "\"for\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,2 @@
import("foo.js",);
import("foo.json", { assert: { type: "json" } },);

View File

@ -0,0 +1,150 @@
{
"type": "Script",
"span": {
"start": 1,
"end": 70,
"ctxt": 0
},
"body": [
{
"type": "ExpressionStatement",
"span": {
"start": 1,
"end": 19,
"ctxt": 0
},
"expression": {
"type": "CallExpression",
"span": {
"start": 1,
"end": 18,
"ctxt": 0
},
"callee": {
"type": "Import",
"span": {
"start": 1,
"end": 7,
"ctxt": 0
}
},
"arguments": [
{
"spread": null,
"expression": {
"type": "StringLiteral",
"span": {
"start": 8,
"end": 16,
"ctxt": 0
},
"value": "foo.js",
"raw": "\"foo.js\""
}
}
],
"typeArguments": null
}
},
{
"type": "ExpressionStatement",
"span": {
"start": 20,
"end": 70,
"ctxt": 0
},
"expression": {
"type": "CallExpression",
"span": {
"start": 20,
"end": 69,
"ctxt": 0
},
"callee": {
"type": "Import",
"span": {
"start": 20,
"end": 26,
"ctxt": 0
}
},
"arguments": [
{
"spread": null,
"expression": {
"type": "StringLiteral",
"span": {
"start": 27,
"end": 37,
"ctxt": 0
},
"value": "foo.json",
"raw": "\"foo.json\""
}
},
{
"spread": null,
"expression": {
"type": "ObjectExpression",
"span": {
"start": 39,
"end": 67,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 41,
"end": 47,
"ctxt": 0
},
"value": "assert",
"optional": false
},
"value": {
"type": "ObjectExpression",
"span": {
"start": 49,
"end": 65,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 51,
"end": 55,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 57,
"end": 63,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
]
}
}
],
"typeArguments": null
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,2 @@
import foo from "foo" assert { type: "json", }
export { default as foo } from "foo" assert { type: "json", }

View File

@ -0,0 +1,166 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 109,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 47,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "foo",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 17,
"end": 22,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 30,
"end": 47,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 32,
"end": 36,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 38,
"end": 44,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
},
{
"type": "ExportNamedDeclaration",
"span": {
"start": 48,
"end": 109,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 57,
"end": 71,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 57,
"end": 64,
"ctxt": 0
},
"value": "default",
"optional": false
},
"exported": {
"type": "Identifier",
"span": {
"start": 68,
"end": 71,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 79,
"end": 84,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 92,
"end": 109,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "Identifier",
"span": {
"start": 94,
"end": 98,
"ctxt": 0
},
"value": "type",
"optional": false
},
"value": {
"type": "StringLiteral",
"span": {
"start": 100,
"end": 106,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,4 @@
import foo, { bar } from "foo" assert {};
import * as ns from "foo" assert {};
export { quux } from "foo" assert {};
export * as ns2 from "foo" assert {};

View File

@ -0,0 +1,225 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 155,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 42,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 8,
"end": 11,
"ctxt": 0
},
"value": "foo",
"optional": false
}
},
{
"type": "ImportSpecifier",
"span": {
"start": 15,
"end": 18,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 15,
"end": 18,
"ctxt": 0
},
"value": "bar",
"optional": false
},
"imported": null,
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 26,
"end": 31,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 39,
"end": 41,
"ctxt": 0
},
"properties": []
}
},
{
"type": "ImportDeclaration",
"span": {
"start": 43,
"end": 79,
"ctxt": 0
},
"specifiers": [
{
"type": "ImportNamespaceSpecifier",
"span": {
"start": 50,
"end": 57,
"ctxt": 0
},
"local": {
"type": "Identifier",
"span": {
"start": 55,
"end": 57,
"ctxt": 0
},
"value": "ns",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 63,
"end": 68,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 76,
"end": 78,
"ctxt": 0
},
"properties": []
}
},
{
"type": "ExportNamedDeclaration",
"span": {
"start": 80,
"end": 117,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 89,
"end": 93,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 89,
"end": 93,
"ctxt": 0
},
"value": "quux",
"optional": false
},
"exported": null,
"isTypeOnly": false
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 101,
"end": 106,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 114,
"end": 116,
"ctxt": 0
},
"properties": []
}
},
{
"type": "ExportNamedDeclaration",
"span": {
"start": 118,
"end": 155,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportNamespaceSpecifier",
"span": {
"start": 125,
"end": 133,
"ctxt": 0
},
"name": {
"type": "Identifier",
"span": {
"start": 130,
"end": 133,
"ctxt": 0
},
"value": "ns2",
"optional": false
}
}
],
"source": {
"type": "StringLiteral",
"span": {
"start": 139,
"end": 144,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 152,
"end": 154,
"ctxt": 0
},
"properties": []
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
export class Foo {}

View File

@ -0,0 +1,45 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 20,
"ctxt": 0
},
"body": [
{
"type": "ExportDeclaration",
"span": {
"start": 1,
"end": 20,
"ctxt": 0
},
"declaration": {
"type": "ClassDeclaration",
"identifier": {
"type": "Identifier",
"span": {
"start": 14,
"end": 17,
"ctxt": 0
},
"value": "Foo",
"optional": false
},
"declare": false,
"span": {
"start": 8,
"end": 20,
"ctxt": 0
},
"decorators": [],
"body": [],
"superClass": null,
"isAbstract": false,
"typeParams": null,
"superTypeParams": null,
"implements": []
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
export function foo() {}

View File

@ -0,0 +1,53 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 25,
"ctxt": 0
},
"body": [
{
"type": "ExportDeclaration",
"span": {
"start": 1,
"end": 25,
"ctxt": 0
},
"declaration": {
"type": "FunctionDeclaration",
"identifier": {
"type": "Identifier",
"span": {
"start": 17,
"end": 20,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"declare": false,
"params": [],
"decorators": [],
"span": {
"start": 8,
"end": 25,
"ctxt": 0
},
"body": {
"type": "BlockStatement",
"span": {
"start": 23,
"end": 25,
"ctxt": 0
},
"stmts": []
},
"generator": false,
"async": false,
"typeParameters": null,
"returnType": null
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
export const foo = "";

View File

@ -0,0 +1,61 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 23,
"ctxt": 0
},
"body": [
{
"type": "ExportDeclaration",
"span": {
"start": 1,
"end": 23,
"ctxt": 0
},
"declaration": {
"type": "VariableDeclaration",
"span": {
"start": 8,
"end": 23,
"ctxt": 0
},
"kind": "const",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 14,
"end": 22,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 14,
"end": 17,
"ctxt": 0
},
"value": "foo",
"optional": false,
"typeAnnotation": null
},
"init": {
"type": "StringLiteral",
"span": {
"start": 20,
"end": 22,
"ctxt": 0
},
"value": "",
"raw": "\"\""
},
"definite": false
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1,3 @@
const foo = "";
export { foo };

View File

@ -0,0 +1,86 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 33,
"ctxt": 0
},
"body": [
{
"type": "VariableDeclaration",
"span": {
"start": 1,
"end": 16,
"ctxt": 0
},
"kind": "const",
"declare": false,
"declarations": [
{
"type": "VariableDeclarator",
"span": {
"start": 7,
"end": 15,
"ctxt": 0
},
"id": {
"type": "Identifier",
"span": {
"start": 7,
"end": 10,
"ctxt": 0
},
"value": "foo",
"optional": false,
"typeAnnotation": null
},
"init": {
"type": "StringLiteral",
"span": {
"start": 13,
"end": 15,
"ctxt": 0
},
"value": "",
"raw": "\"\""
},
"definite": false
}
]
},
{
"type": "ExportNamedDeclaration",
"span": {
"start": 18,
"end": 33,
"ctxt": 0
},
"specifiers": [
{
"type": "ExportSpecifier",
"span": {
"start": 27,
"end": 30,
"ctxt": 0
},
"orig": {
"type": "Identifier",
"span": {
"start": 27,
"end": 30,
"ctxt": 0
},
"value": "foo",
"optional": false
},
"exported": null,
"isTypeOnly": false
}
],
"source": null,
"typeOnly": false,
"with": null
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
import "foo" assert { "type": "json" };

View File

@ -0,0 +1,64 @@
{
"type": "Module",
"span": {
"start": 1,
"end": 40,
"ctxt": 0
},
"body": [
{
"type": "ImportDeclaration",
"span": {
"start": 1,
"end": 40,
"ctxt": 0
},
"specifiers": [],
"source": {
"type": "StringLiteral",
"span": {
"start": 8,
"end": 13,
"ctxt": 0
},
"value": "foo",
"raw": "\"foo\""
},
"typeOnly": false,
"with": {
"type": "ObjectExpression",
"span": {
"start": 21,
"end": 39,
"ctxt": 0
},
"properties": [
{
"type": "KeyValueProperty",
"key": {
"type": "StringLiteral",
"span": {
"start": 23,
"end": 29,
"ctxt": 0
},
"value": "type",
"raw": "\"type\""
},
"value": {
"type": "StringLiteral",
"span": {
"start": 31,
"end": 37,
"ctxt": 0
},
"value": "json",
"raw": "\"json\""
}
}
]
}
}
],
"interpreter": null
}

View File

@ -0,0 +1 @@
export * as foo from "foo.json" assert { type: "json" };

Some files were not shown because too many files have changed in this diff Show More