@@ -61,6 +61,13 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
6161 /// module.
6262 final memberNames = < Member , String > {};
6363
64+ /// Maps each `Procedure` node compiled in the module to the `Identifier` s
65+ /// used to name the class in JavaScript.
66+ ///
67+ /// This mapping is used when generating the symbol information for the
68+ /// module.
69+ final procedureIdentifiers = < Procedure , js_ast.Identifier > {};
70+
6471 /// Maps each `VariableDeclaration` node compiled in the module to the name
6572 /// used for the variable in JavaScript.
6673 ///
@@ -1670,7 +1677,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
16701677 ctorFields = ctor.initializers
16711678 .map ((c) => c is FieldInitializer ? c.field : null )
16721679 .toSet ()
1673- ..remove (null );
1680+ ..remove (null );
16741681 }
16751682
16761683 var body = < js_ast.Statement > [];
@@ -2368,8 +2375,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
23682375 Class memberClass}) {
23692376 // Static members skip the rename steps and may require JS interop renames.
23702377 if (isStatic) {
2371- // TODO(nshahan) Record the name for this member in memberNames.
2372- return _emitStaticMemberName (name, member);
2378+ var memberName = _emitStaticMemberName (name, member);
2379+ memberNames[member] = memberName.valueWithoutQuotes;
2380+ return memberName;
23732381 }
23742382
23752383 // We allow some (illegal in Dart) member names to be used in our private
@@ -2379,6 +2387,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
23792387 var runtimeName = _jsExportName (member);
23802388 if (runtimeName != null ) {
23812389 var parts = runtimeName.split ('.' );
2390+ // TODO(nshahan) Record the name for this member in memberNames.
23822391 if (parts.length < 2 ) return propertyName (runtimeName);
23832392
23842393 js_ast.Expression result = _emitIdentifier (parts[0 ]);
@@ -2652,8 +2661,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
26522661 _currentUri = node.fileUri;
26532662
26542663 var name = node.name.text;
2664+ memberNames[node] = name;
26552665 var result = js_ast.Method (
2656- propertyName (name), _emitFunction (node.function, node. name.text ),
2666+ propertyName (name), _emitFunction (node.function, name),
26572667 isGetter: node.isGetter, isSetter: node.isSetter)
26582668 ..sourceInformation = _nodeEnd (node.fileEndOffset);
26592669
@@ -2678,8 +2688,10 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
26782688
26792689 var nameExpr = _emitTopLevelName (p);
26802690 var jsName = _safeFunctionNameForSafari (p.name.text, fn);
2681- body.add (js.statement ('# = #' ,
2682- [nameExpr, js_ast.NamedFunction (_emitTemporaryId (jsName), fn)]));
2691+ var functionName = _emitTemporaryId (jsName);
2692+ procedureIdentifiers[p] = functionName;
2693+ body.add (js.statement (
2694+ '# = #' , [nameExpr, js_ast.NamedFunction (functionName, fn)]));
26832695
26842696 _currentUri = savedUri;
26852697 _staticTypeContext.leaveMember (p);
@@ -2872,27 +2884,15 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
28722884 js_ast.Expression typeRep;
28732885
28742886 // Type parameters don't matter as JS interop types cannot be reified.
2875- // We have to use lazy JS types because until we have proper module
2876- // loading for JS libraries bundled with Dart libraries, we will sometimes
2877- // need to load Dart libraries before the corresponding JS libraries are
2878- // actually loaded.
2879- // Given a JS type such as:
2880- // @JS('google.maps.Location')
2881- // class Location { ... }
2882- // We can't emit a reference to MyType because the JS library that defines
2883- // it may be loaded after our code. So for now, we use a special lazy type
2884- // object to represent MyType.
2885- // Anonymous JS types do not have a corresponding concrete JS type so we
2886- // have to use a helper to define them.
2887- if (isJSAnonymousType (c)) {
2888- typeRep = runtimeCall (
2889- 'anonymousJSType(#)' , [js.escapedString (getLocalClassName (c))]);
2890- } else {
2891- var jsName = _emitJsNameWithoutGlobal (c);
2892- if (jsName != null ) {
2893- typeRep = runtimeCall ('lazyJSType(() => #, #)' ,
2894- [_emitJSInteropForGlobal (jsName), js.escapedString (jsName)]);
2895- }
2887+ // package:js types fall under either named or anonymous types. Named types
2888+ // are used to correspond to JS types that exist, but we do not use the
2889+ // underlying type for type checks, so they operate virtually the same as
2890+ // anonymous types. We represent package:js types with a corresponding type
2891+ // object.
2892+ var jsName = isJSAnonymousType (c) ?
2893+ getLocalClassName (c) : _emitJsNameWithoutGlobal (c);
2894+ if (jsName != null ) {
2895+ typeRep = runtimeCall ('packageJSType(#)' , [js.escapedString (jsName)]);
28962896 }
28972897
28982898 if (typeRep != null ) {
@@ -3605,7 +3605,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
36053605 }
36063606
36073607 for (var p in f.positionalParameters) {
3608- var jsParam = _emitVariableDef (p);
3608+ var jsParam = _emitVariableRef (p);
36093609 if (_checkParameters) {
36103610 initParameter (p, jsParam);
36113611 }
@@ -4510,21 +4510,19 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
45104510 var name = v.name;
45114511 if (name == null || name.startsWith ('#' )) {
45124512 name = name == null ? 't${_tempVariables .length }' : name.substring (1 );
4513- // TODO(nshahan) Record the Identifier for this variable in
4514- // variableIdentifiers.
45154513 return _tempVariables.putIfAbsent (v, () => _emitTemporaryId (name));
45164514 }
4517- var identifier = _emitIdentifier (name);
4518- variableIdentifiers[v] = identifier;
4519- return identifier;
4515+ return _emitIdentifier (name);
45204516 }
45214517
45224518 /// Emits the declaration of a variable.
45234519 ///
45244520 /// This is similar to [_emitVariableRef] but it also attaches source
45254521 /// location information, so hover will work as expected.
45264522 js_ast.Identifier _emitVariableDef (VariableDeclaration v) {
4527- return _emitVariableRef (v)..sourceInformation = _nodeStart (v);
4523+ var identifier = _emitVariableRef (v)..sourceInformation = _nodeStart (v);
4524+ variableIdentifiers[v] = identifier;
4525+ return identifier;
45284526 }
45294527
45304528 js_ast.Statement _initLetVariables () {
@@ -6403,8 +6401,9 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
64036401 Library library, String className, Member member,
64046402 [js_ast.TemporaryId id]) {
64056403 var name = '$className .${member .name .text }' ;
6406- // Names used in the symbols for the public fields
6407- // memberNames[member] = 'Symbol($name)';
6404+ // Wrap the name as a symbol here so it matches what you would find at
6405+ // runtime when you get all properties and symbols from an instance.
6406+ memberNames[member] = 'Symbol($name )' ;
64086407 return emitPrivateNameSymbol (library, name, id);
64096408 }
64106409
0 commit comments