Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Rename ImportDeclaration attributes to assertions
Browse files Browse the repository at this point in the history
Summary:
ESTree refers to these as assertions.

Fix facebook#607

Reviewed By: tmikov, neildhar

Differential Revision: D31383961

fbshipit-source-id: 78000a59591df52b222057c865ea3bdc2b258a46
  • Loading branch information
avp authored and facebook-github-bot committed Oct 5, 2021
1 parent ec424a1 commit e4b4cb9
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion include/hermes/AST/ESTree.def
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ ESTREE_NODE_4_ARGS(
ImportDeclaration, Base,
NodeList, specifiers, false,
NodePtr, source, false,
NodeList, attributes, true,
NodeList, assertions, true,
NodeLabel, importKind, false)

ESTREE_NODE_3_ARGS(
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/SemanticValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void SemanticValidator::visit(ImportDeclarationNode *importDecl) {
"'import' statement requires module mode");
}

if (compile_ && !importDecl->_attributes.empty()) {
if (compile_ && !importDecl->_assertions.empty()) {
sm_.error(
importDecl->getSourceRange(), "import assertions are not supported");
}
Expand Down
12 changes: 6 additions & 6 deletions test/Parser/es6/import-assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'foo.js' assert {};
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: },

Expand All @@ -31,7 +31,7 @@ import 'foo.js' assert {type: 'json'};
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [
// CHECK-NEXT: "assertions": [
// CHECK-NEXT: {
// CHECK-NEXT: "type": "ImportAttribute",
// CHECK-NEXT: "key": {
Expand All @@ -55,7 +55,7 @@ import 'foo.js' assert {'type': 'json'};
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [
// CHECK-NEXT: "assertions": [
// CHECK-NEXT: {
// CHECK-NEXT: "type": "ImportAttribute",
// CHECK-NEXT: "key": {
Expand All @@ -79,7 +79,7 @@ import 'foo.js' assert {'type': 'json',};
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [
// CHECK-NEXT: "assertions": [
// CHECK-NEXT: {
// CHECK-NEXT: "type": "ImportAttribute",
// CHECK-NEXT: "key": {
Expand All @@ -103,7 +103,7 @@ import 'foo.js' assert {'type': 'json', 'foo': 'bar', };
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [
// CHECK-NEXT: "assertions": [
// CHECK-NEXT: {
// CHECK-NEXT: "type": "ImportAttribute",
// CHECK-NEXT: "key": {
Expand Down Expand Up @@ -138,7 +138,7 @@ import 'foo.js' assert {'type': 'json', 'foo': 'bar', };
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [
// CHECK-NEXT: "assertions": [
// CHECK-NEXT: {
// CHECK-NEXT: "type": "ImportAttribute",
// CHECK-NEXT: "key": {
Expand Down
2 changes: 1 addition & 1 deletion test/Parser/es6/import-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ import {foo, bar as baz} from 'other';
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value",
// CHECK-NEXT: "loc": {
// CHECK-NEXT: "start": {
Expand Down
16 changes: 8 additions & 8 deletions test/Parser/es6/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'foo.js';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: },

Expand All @@ -39,7 +39,7 @@ import * as Foo from 'foo.js';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: },

Expand All @@ -64,7 +64,7 @@ import { x as y } from 'foo.js';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: },

Expand All @@ -89,7 +89,7 @@ import { x } from 'foo.js';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: },

Expand Down Expand Up @@ -138,7 +138,7 @@ import { abc, xyz as def, ghi , } from 'foo.js';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: },

Expand All @@ -163,7 +163,7 @@ import { catch as valid } from 'foo.js';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: },

Expand All @@ -183,7 +183,7 @@ import defaultFoo from 'foo.js';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: },

Expand All @@ -210,7 +210,7 @@ import defaultBar, * as Bar from 'bar.js';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "bar.js"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: }

Expand Down
2 changes: 1 addition & 1 deletion test/Parser/flow/declare-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ declare module WithImport {
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "Foo"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "type"
// CHECK-NEXT: }
// CHECK-NEXT: ]
Expand Down
4 changes: 2 additions & 2 deletions test/Parser/flow/import-location.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import typeof Foo, {bar} from 'foo';
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "type",
// CHECK-NEXT: "loc": {
// CHECK-NEXT: "start": {
Expand Down Expand Up @@ -161,7 +161,7 @@ import typeof Foo, {bar} from 'foo';
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "typeof",
// CHECK-NEXT: "loc": {
// CHECK-NEXT: "start": {
Expand Down
12 changes: 6 additions & 6 deletions test/Parser/flow/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import typeof x from 'foo';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "typeof"
// CHECK-NEXT: },

Expand All @@ -47,7 +47,7 @@ import type x from 'foo';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "type"
// CHECK-NEXT: },

Expand All @@ -72,7 +72,7 @@ import { type type } from 'foo';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: },

Expand All @@ -97,7 +97,7 @@ import { type type as type } from 'foo';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: },

Expand All @@ -122,7 +122,7 @@ import { type T as U } from 'foo';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: },

Expand All @@ -142,6 +142,6 @@ import type from 'foo';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "value"
// CHECK-NEXT: }
2 changes: 1 addition & 1 deletion test/Parser/ts/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ import type {x} from 'foo';
// CHECK-NEXT: "type": "StringLiteral",
// CHECK-NEXT: "value": "foo"
// CHECK-NEXT: },
// CHECK-NEXT: "attributes": [],
// CHECK-NEXT: "assertions": [],
// CHECK-NEXT: "importKind": "type"
// CHECK-NEXT: }
2 changes: 1 addition & 1 deletion unsupported/juno/crates/hermes/src/parser/generated_ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ extern "C" {
// ImportDeclaration
pub fn hermes_get_ImportDeclaration_specifiers(node: NodePtr) -> NodeListRef;
pub fn hermes_get_ImportDeclaration_source(node: NodePtr) -> NodePtr;
pub fn hermes_get_ImportDeclaration_attributes(node: NodePtr) -> NodeListOptRef;
pub fn hermes_get_ImportDeclaration_assertions(node: NodePtr) -> NodeListOptRef;
pub fn hermes_get_ImportDeclaration_importKind(node: NodePtr) -> NodeLabel;
// ImportSpecifier
pub fn hermes_get_ImportSpecifier_imported(node: NodePtr) -> NodePtr;
Expand Down
2 changes: 1 addition & 1 deletion unsupported/juno/crates/juno/src/ast/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ macro_rules! nodekind_defs {
ImportDeclaration[Declaration] {
specifiers: NodeList[ImportSpecifier],
source: NodePtr[StringLiteral],
attributes: Option<NodeList>[ImportAttribute],
assertions: Option<NodeList>[ImportAttribute],
import_kind: ImportKind,
},
ImportSpecifier {
Expand Down
8 changes: 4 additions & 4 deletions unsupported/juno/crates/juno/src/gen_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ impl<W: Write> GenJS<W> {
range: _,
specifiers,
source,
attributes,
assertions,
import_kind,
}) => {
out_token!(self, node.get(ctx), "import ");
Expand Down Expand Up @@ -1380,10 +1380,10 @@ impl<W: Write> GenJS<W> {
out!(self, "from ");
}
source.visit(ctx, self, Some(node));
if let Some(attributes) = attributes {
if !attributes.is_empty() {
if let Some(assertions) = assertions {
if !assertions.is_empty() {
out!(self, " assert {{");
for (i, attribute) in attributes.iter().enumerate() {
for (i, attribute) in assertions.iter().enumerate() {
if i > 0 {
self.comma();
}
Expand Down
4 changes: 2 additions & 2 deletions unsupported/juno/crates/juno/src/hparser/generated_cvt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,14 +846,14 @@ pub unsafe fn cvt_node_ptr(cvt: &mut Converter, n: NodePtr) -> ast::NodePtr {
NodeKind::ImportDeclaration => {
let specifiers = cvt_node_list(cvt, hermes_get_ImportDeclaration_specifiers(n));
let source = cvt_node_ptr(cvt, hermes_get_ImportDeclaration_source(n));
let attributes = cvt_node_list_opt(cvt, hermes_get_ImportDeclaration_attributes(n));
let assertions = cvt_node_list_opt(cvt, hermes_get_ImportDeclaration_assertions(n));
let import_kind = cvt_enum(hermes_get_ImportDeclaration_importKind(n));
cvt.ast_context.alloc(
ast::Node::ImportDeclaration(ast::ImportDeclaration {
range,
specifiers,
source,
attributes,
assertions,
import_kind,
}),
)
Expand Down
2 changes: 1 addition & 1 deletion utils/testsuite/esprima_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TestStatus(enum.IntEnum):
# key is the type of a node, and value is the set of keys of a child node that
# needs to be omitted.
HERMES_OMITTED_KEYS = {
"ImportDeclaration": {"importKind", "attributes"},
"ImportDeclaration": {"importKind", "assertions"},
"ImportSpecifier": {"importKind"},
"ExportNamedDeclaration": {"exportKind"},
"ExportAllDeclaration": {"exportKind"},
Expand Down

0 comments on commit e4b4cb9

Please sign in to comment.