@@ -173,8 +173,47 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
173173 if (_rewriter._writeStaticInit) {
174174 // rewrite bootstrap import to its static version.
175175 buf.write (_rewriter._code.substring (_currentIndex, node.offset));
176- // TODO(yjbanov): handle import "..." show/hide ...
177- buf.write ("import '$BOOTSTRAP_STATIC_URI ';" );
176+ buf.write ("import '$BOOTSTRAP_STATIC_URI '" );
177+
178+ // The index of the last character we've processed.
179+ var lastIdx = node.uri.end;
180+
181+ // Maintain the import prefix, if present.
182+ if (node.prefix != null ) {
183+ buf.write (_rewriter._code.substring (lastIdx, node.prefix.end));
184+ lastIdx = node.prefix.end;
185+ }
186+
187+ // Handle combinators ("show" and "hide" on an "import" directive).
188+ // 1. A combinator like "show $BOOTSTRAP_NAME" no longer makes sense, so
189+ // we need to rewrite it.
190+ // 2. It's possible we'll need to call the setup method
191+ // (SETUP_METHOD_NAME), so make sure it is visible.
192+ if (node.combinators != null ) {
193+ for (var combinator in node.combinators) {
194+ buf.write (_rewriter._code
195+ .substring (lastIdx, combinator.end)
196+ .replaceAll (BOOTSTRAP_NAME , BOOTSTRAP_STATIC_NAME ));
197+ lastIdx = combinator.end;
198+ if (combinator is ShowCombinator ) {
199+ buf.write (', $SETUP_METHOD_NAME ' );
200+ } else if (combinator is HideCombinator ) {
201+ // Ensure the user is not explicitly hiding SETUP_METHOD_NAME.
202+ // I don't know why anyone would do this, but it would result in
203+ // some confusing behavior, so throw an explicit error.
204+ combinator.hiddenNames.forEach ((id) {
205+ if (id.toString () == SETUP_METHOD_NAME ) {
206+ throw new FormatException (
207+ 'Import statement explicitly hides initialization function '
208+ '$SETUP_METHOD_NAME . Please do not do this: "$node "' );
209+ }
210+ });
211+ }
212+ }
213+ }
214+
215+ // Write anything after the combinators.
216+ buf.write (_rewriter._code.substring (lastIdx, node.end));
178217 _hasStaticBootstrapImport = true ;
179218 } else {
180219 // leave it as is
@@ -198,6 +237,10 @@ class _RewriterVisitor extends Object with RecursiveAstVisitor<Object> {
198237 _setupAdded ? '' : ', () { ${_getStaticReflectorInitBlock ()} }' ;
199238
200239 // rewrite `bootstrap(...)` to `bootstrapStatic(...)`
240+ if (node.target != null && node.target is SimpleIdentifier ) {
241+ // `bootstrap` imported with a prefix, maintain this.
242+ buf.write ('${node .target }.' );
243+ }
201244 buf.write ('$BOOTSTRAP_STATIC_NAME (${args [0 ]}' );
202245 if (numArgs == 1 ) {
203246 // bootstrap args are positional, so before we pass reflectorInit code
0 commit comments