@@ -39,6 +39,20 @@ class ES2015Module extends Module {
39
39
// modules are implicitly strict
40
40
any ( )
41
41
}
42
+
43
+ /**
44
+ * Holds if this module contains both named and `default` exports.
45
+ *
46
+ * This is used to determine whether a default-import of the module should be reinterpreted
47
+ * as a namespace-import, to accommodate the non-standard behavior implemented by some compilers.
48
+ *
49
+ * When a module has both named and `default` exports, the non-standard interpretation can lead to
50
+ * ambiguities, so we only allow the standard interpretation in that case.
51
+ */
52
+ predicate hasBothNamedAndDefaultExports ( ) {
53
+ hasNamedExports ( this ) and
54
+ hasDefaultExport ( this )
55
+ }
42
56
}
43
57
44
58
/**
@@ -64,17 +78,6 @@ private predicate hasDefaultExport(ES2015Module mod) {
64
78
mod .getAnExport ( ) .( ExportNamedDeclaration ) .getASpecifier ( ) .getExportedName ( ) = "default"
65
79
}
66
80
67
- /**
68
- * Holds if `mod` contains both named and `default` exports.
69
- *
70
- * This is used to determine whether a default-import of the module should be reinterpreted
71
- * as a namespace-import, to accommodate the non-standard behavior implemented by some compilers.
72
- */
73
- private predicate hasBothNamedAndDefaultExports ( ES2015Module mod ) {
74
- hasNamedExports ( mod ) and
75
- hasDefaultExport ( mod )
76
- }
77
-
78
81
/**
79
82
* An import declaration.
80
83
*
@@ -131,7 +134,7 @@ class ImportDeclaration extends Stmt, Import, @import_declaration {
131
134
// For compatibility with the non-standard implementation of default imports,
132
135
// treat default imports as namespace imports in cases where it can't cause ambiguity
133
136
// between named exports and the properties of a default-exported object.
134
- not hasBothNamedAndDefaultExports ( this .getImportedModule ( ) ) and
137
+ not this .getImportedModule ( ) . ( ES2015Module ) . hasBothNamedAndDefaultExports ( ) and
135
138
is .getImportedName ( ) = "default"
136
139
)
137
140
or
0 commit comments