Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: lib/src/codegen/js_codegen.dart

Issue 1088663002: fix sunflower -- dom types were not resolving (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dev_compiler.src.codegen.js_codegen; 5 library dev_compiler.src.codegen.js_codegen;
6 6
7 import 'dart:collection' show HashSet, HashMap; 7 import 'dart:collection' show HashSet, HashMap;
8 import 'dart:io' show Directory, File; 8 import 'dart:io' show Directory, File;
9 9
10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator; 10 import 'package:analyzer/analyzer.dart' hide ConstantEvaluator;
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 326
327 var name = node.name.name; 327 var name = node.name.name;
328 var heritage = 328 var heritage =
329 js.call('dart.mixin(#)', [_visitList(node.withClause.mixinTypes)]); 329 js.call('dart.mixin(#)', [_visitList(node.withClause.mixinTypes)]);
330 var classDecl = new JS.ClassDeclaration( 330 var classDecl = new JS.ClassDeclaration(
331 new JS.ClassExpression(new JS.Identifier(name), heritage, [])); 331 new JS.ClassExpression(new JS.Identifier(name), heritage, []));
332 332
333 return _finishClassDef(type, classDecl); 333 return _finishClassDef(type, classDecl);
334 } 334 }
335 335
336 JS.Statement _emitJsType(ClassDeclaration node, Annotation jsName) {
337 var dartName = node.name.name;
338 String jsTypeName = null;
339
340 if (jsName.arguments != null) {
341 var args = jsName.arguments.arguments;
342 if (args.isNotEmpty && args[0] is NamedExpression) {
343 NamedExpression named = args[0];
Jacob 2015/04/13 19:27:14 seems like we should add a helper method to extrac
Jennifer Messerly 2015/04/13 20:02:10 Sure thing. Ultimately we need these in analyzer t
344 if (named.name.label.name == 'name' &&
345 named.expression is StringLiteral) {
346 jsTypeName = (named.expression as StringLiteral).stringValue;
347 }
348 }
349 }
350
351 // We export the JS type as if it was a Dart type. For example this allows
352 // `dom.InputElement` to actually be HTMLInputElement.
353 // TODO(jmesserly): if we had the JS name on the Element, we could
354 if (isPublic(dartName)) _addExport(dartName);
355
356 if (jsTypeName != null && jsTypeName != dartName) {
357 return js.statement('let # = #;', [dartName, jsTypeName]);
358 }
359 return null;
360 }
361
336 @override 362 @override
337 JS.Statement visitClassDeclaration(ClassDeclaration node) { 363 JS.Statement visitClassDeclaration(ClassDeclaration node) {
338 // If we've already emitted this class, skip it. 364 // If we've already emitted this class, skip it.
339 var type = node.element.type; 365 var type = node.element.type;
340 if (_pendingClasses.remove(node.element) == null) return null; 366 if (_pendingClasses.remove(node.element) == null) return null;
341 if (_getJsNameAnnotation(node) != null) return null; 367
368 var jsName = _getJsNameAnnotation(node);
369 if (jsName != null) return _emitJsType(node, jsName);
342 370
343 currentClass = node; 371 currentClass = node;
344 372
345 var ctors = <ConstructorDeclaration>[]; 373 var ctors = <ConstructorDeclaration>[];
346 var fields = <FieldDeclaration>[]; 374 var fields = <FieldDeclaration>[];
347 var staticFields = <FieldDeclaration>[]; 375 var staticFields = <FieldDeclaration>[];
348 for (var member in node.members) { 376 for (var member in node.members) {
349 if (member is ConstructorDeclaration) { 377 if (member is ConstructorDeclaration) {
350 ctors.add(member); 378 ctors.add(member);
351 } else if (member is FieldDeclaration) { 379 } else if (member is FieldDeclaration) {
(...skipping 2217 matching lines...) Expand 10 before | Expand all | Expand 10 after
2569 if (parent is MethodInvocation && 2597 if (parent is MethodInvocation &&
2570 identical(parent.methodName, node)) return; 2598 identical(parent.methodName, node)) return;
2571 if (parent is ConstructorName) return; 2599 if (parent is ConstructorName) return;
2572 if (parent is Label) return; 2600 if (parent is Label) return;
2573 2601
2574 if (node.inSetterContext() && node.staticElement == _variable) { 2602 if (node.inSetterContext() && node.staticElement == _variable) {
2575 _potentiallyMutated = true; 2603 _potentiallyMutated = true;
2576 } 2604 }
2577 } 2605 }
2578 } 2606 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698