Skip to content

Commit c28004f

Browse files
committed
Rename 'getImportAssertion()' to 'getImportAttributes()' in QL library
1 parent 07172da commit c28004f

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-15
lines changed

javascript/ql/lib/semmle/javascript/ES2015Modules.qll

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,27 @@ class ImportDeclaration extends Stmt, Import, @import_declaration {
9191
override PathExpr getImportedPath() { result = this.getChildExpr(-1) }
9292

9393
/**
94-
* Gets the object literal passed as part of the `assert` clause in this import declaration.
94+
* Gets the object literal passed as part of the `with` (or `assert`) clause in this import declaration.
9595
*
9696
* For example, this gets the `{ type: "json" }` object literal in the following:
9797
* ```js
98+
* import foo from "foo" with { type: "json" };
9899
* import foo from "foo" assert { type: "json" };
99100
* ```
100101
*/
101-
ObjectExpr getImportAssertion() { result = this.getChildExpr(-10) }
102+
ObjectExpr getImportAttributes() { result = this.getChildExpr(-10) }
103+
104+
/**
105+
* DEPRECATED: use `getImportAttributes` instead.
106+
* Gets the object literal passed as part of the `with` (or `assert`) clause in this import declaration.
107+
*
108+
* For example, this gets the `{ type: "json" }` object literal in the following:
109+
* ```js
110+
* import foo from "foo" with { type: "json" };
111+
* import foo from "foo" assert { type: "json" };
112+
* ```
113+
*/
114+
deprecated ObjectExpr getImportAssertion() { result = this.getImportAttributes() }
102115

103116
/** Gets the `i`th import specifier of this import declaration. */
104117
ImportSpecifier getSpecifier(int i) { result = this.getChildExpr(i) }
@@ -322,17 +335,33 @@ abstract class ExportDeclaration extends Stmt, @export_declaration {
322335
override string getAPrimaryQlClass() { result = "ExportDeclaration" }
323336

324337
/**
325-
* Gets the object literal passed as part of the `assert` clause, if this is
338+
* Gets the object literal passed as part of the `with` (or `assert`) clause, if this is
339+
* a re-export declaration.
340+
*
341+
* For example, this gets the `{ type: "json" }` expression in each of the following:
342+
* ```js
343+
* export { x } from 'foo' with { type: "json" };
344+
* export * from 'foo' with { type: "json" };
345+
* export * as x from 'foo' with { type: "json" };
346+
* export * from 'foo' assert { type: "json" };
347+
* ```
348+
*/
349+
ObjectExpr getImportAttributes() { result = this.getChildExpr(-10) }
350+
351+
/**
352+
* DEPRECATED: use `getImportAttributes` instead.
353+
* Gets the object literal passed as part of the `with` (or `assert`) clause, if this is
326354
* a re-export declaration.
327355
*
328356
* For example, this gets the `{ type: "json" }` expression in each of the following:
329357
* ```js
330-
* export { x } from 'foo' assert { type: "json" };
358+
* export { x } from 'foo' with { type: "json" };
359+
* export * from 'foo' with { type: "json" };
360+
* export * as x from 'foo' with { type: "json" };
331361
* export * from 'foo' assert { type: "json" };
332-
* export * as x from 'foo' assert { type: "json" };
333362
* ```
334363
*/
335-
ObjectExpr getImportAssertion() { result = this.getChildExpr(-10) }
364+
deprecated ObjectExpr getImportAssertion() { result = this.getImportAttributes() }
336365
}
337366

338367
/**

javascript/ql/lib/semmle/javascript/Expr.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,7 +2807,7 @@ class FunctionBindExpr extends @bind_expr, Expr {
28072807
*
28082808
* ```
28092809
* import("fs")
2810-
* import("foo", { assert: { type: "json" }})
2810+
* import("foo", { with: { type: "json" }})
28112811
* ```
28122812
*/
28132813
class DynamicImportExpr extends @dynamic_import, Expr, Import {
@@ -2823,9 +2823,9 @@ class DynamicImportExpr extends @dynamic_import, Expr, Import {
28232823
/**
28242824
* Gets the second "argument" to the import expression, that is, the `Y` in `import(X, Y)`.
28252825
*
2826-
* For example, gets the `{ assert: { type: "json" }}` expression in the following:
2826+
* For example, gets the `{ with: { type: "json" }}` expression in the following:
28272827
* ```js
2828-
* import('foo', { assert: { type: "json" }})
2828+
* import('foo', { with: { type: "json" }})
28292829
* ```
28302830
*/
28312831
Expr getImportAttributes() { result = this.getChildExpr(1) }

javascript/ql/test/library-tests/TypeScript/ImportAssertions/test.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
getImportAssertionFromImport
1+
getImportAttributesFromImport
22
| js-import-assertions.js:1:1:1:40 | import ... son" }; | js-import-assertions.js:1:24:1:39 | { type: "json" } |
33
| js-import-assertions.js:2:1:2:53 | import ... son" }; | js-import-assertions.js:2:37:2:52 | { type: "json" } |
44
| js-import-assertions.js:3:1:3:52 | import ... son" }; | js-import-assertions.js:3:36:3:51 | { type: "json" } |
@@ -7,7 +7,7 @@ getImportAssertionFromImport
77
| ts-import-assertions.ts:4:1:4:53 | import ... son" }; | ts-import-assertions.ts:4:37:4:52 | { type: "json" } |
88
| ts-import-assertions.ts:5:1:5:52 | import ... son" }; | ts-import-assertions.ts:5:36:5:51 | { type: "json" } |
99
| ts-import-assertions.ts:6:1:6:48 | import ... son" }; | ts-import-assertions.ts:6:32:6:47 | { type: "json" } |
10-
getImportAssertionFromExport
10+
getImportAttributesFromExport
1111
| js-import-assertions.js:6:1:6:52 | export ... son" }; | js-import-assertions.js:6:36:6:51 | { type: "json" } |
1212
| js-import-assertions.js:7:1:7:47 | export ... son" }; | js-import-assertions.js:7:31:7:46 | { type: "json" } |
1313
| js-import-assertions.js:8:1:8:53 | export ... son" }; | js-import-assertions.js:8:37:8:52 | { type: "json" } |

javascript/ql/test/library-tests/TypeScript/ImportAssertions/test.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import javascript
22

3-
query Expr getImportAssertionFromImport(ImportDeclaration decl) {
4-
result = decl.getImportAssertion()
3+
query Expr getImportAttributesFromImport(ImportDeclaration decl) {
4+
result = decl.getImportAttributes()
55
}
66

7-
query Expr getImportAssertionFromExport(ExportDeclaration decl) {
8-
result = decl.getImportAssertion()
7+
query Expr getImportAttributesFromExport(ExportDeclaration decl) {
8+
result = decl.getImportAttributes()
99
}
1010

1111
query Expr getImportAttributes(DynamicImportExpr imprt) { result = imprt.getImportAttributes() }

0 commit comments

Comments
 (0)