Good catch. The real solution IMHO to these issues is to do linker processing on a JS AST, not on text. Most of the current linker API relies on string operations which make designing a non-brittle sourcemap difficult. If for example, we read the JS for the fragment via the Closure/Rhino AST, then we could mutate it in all sorts of interesting ways, and let the serialization of the AST take care of updating the source maps.
The class ClosureJsAstTranslator already contains the logic neccessary. What we could do is use it to translate the GWT JsAst to a Closure Ast, and serialize that in the CompilationResult. The linker API could then get the fragments as strings, but could also get the AST if it needed. Manipulating the AST to do things like splitting, wrapping, et al would preserve the sourcemap. -Ray On Tue, Apr 9, 2013 at 11:39 PM, Alex Epshteyn <[email protected] > wrote: > I'm trying to fix a bug ( > https://code.google.com/p/google-web-toolkit/issues/detail?id=8100 > ), and I could use some expert advice. I'm a long time GWT user (7 > years), but only recently started hacking the internals, and I need > help on this one. > > Background: > > SelectionScriptLinker.splitPrimaryJavaScript attempts to check whether > the property "compiler.useSourceMaps" is "true" and if it is, the > method avoids splitting the javascript into chunks (which would > destroy the accuracy of the line numbers in the source map). > > The Problem: > > This method tries to get the property value from > LinkerContext.getProperties, which is not a PropertyOracle, and hence > it can't return the correct property value for the current > permutation. In fact, it will return a null value unless the property > has a static value for all permutations (e.g. <set-property > name="compiler.useSourceMaps" value="true"/>) > > However, something like > > <set-property name="compiler.useSourceMaps" value="true"> > <when-property-is name="user.agent" value="safari"/> > </set-property> > > will not work because SelectionScriptLinker.splitPrimaryJavaScript can > only read static property values. > > Could someone advise me on how to fix this bug? > > Here's is there relevant source code for quick reference: > > public static String splitPrimaryJavaScript(StatementRanges ranges, > String js, > int charsPerChunk, String scriptChunkSeparator, LinkerContext > context) { > boolean useSourceMaps = false; > for (SelectionProperty prop : context.getProperties()) { > if (USE_SOURCE_MAPS_PROPERTY.equals(prop.getName())) { > String str = prop.tryGetValue(); > useSourceMaps = str == null ? false : > Boolean.parseBoolean(str); > break; > } > } > > // TODO(cromwellian) enable chunking with sourcemaps > if (charsPerChunk < 0 || ranges == null || useSourceMaps) { > return js; > } > ... > > -- > -- > http://groups.google.com/group/Google-Web-Toolkit-Contributors > --- > You received this message because you are subscribed to the Google Groups > "Google Web Toolkit Contributors" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- -- http://groups.google.com/group/Google-Web-Toolkit-Contributors --- You received this message because you are subscribed to the Google Groups "Google Web Toolkit Contributors" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
