Package com.github.sommeri.sourcemap

Examples of com.github.sommeri.sourcemap.FilePosition


    generator = SourceMapGeneratorFactory.getInstance(SourceMapFormat.V3);
  }

  public SourceMapBuilder append(String str, HiddenTokenAwareTree sourceToken) {
    //indentation must be handled before measuring symbol start position
    FilePosition outputStartPosition = beforeSymbolPosition();
    cssBuilder.append(str);
    FilePosition outputEndPosition = afterSymbolPosition();

    createMapping(str, sourceToken, outputStartPosition, outputEndPosition);
    return this;
  }
View Full Code Here


    createMapping(str, sourceToken, outputStartPosition, outputEndPosition);
    return this;
  }

  public void appendIgnoreNull(String str, HiddenTokenAwareTree sourceToken) {
    FilePosition outputStartPosition = beforeSymbolPosition();
    cssBuilder.append(str);
    FilePosition outputEndPosition = afterSymbolPosition();

    createMapping(str, sourceToken, outputStartPosition, outputEndPosition);
  }
View Full Code Here

    createMapping(str, sourceToken, outputStartPosition, outputEndPosition);
  }

  private void createMapping(String mappedSymbol, HiddenTokenAwareTree sourceToken, FilePosition outputStartPosition, FilePosition outputEndPosition) {
    FilePosition sourceStartPosition = toFilePosition(sourceToken);
    String sourceName = toSourceName(sourceToken);
    String sourceContent = toSourceContent(sourceToken, sourceName);

    generator.addMapping(sourceName, sourceContent, mappedSymbol, sourceStartPosition, outputStartPosition, outputEndPosition);
  }
View Full Code Here

    generator.addMapping(sourceName, sourceContent, mappedSymbol, sourceStartPosition, outputStartPosition, outputEndPosition);
  }

  private FilePosition beforeSymbolPosition() {
    cssBuilder.handleIndentation();
    FilePosition outputStartPosition = afterSymbolPosition();
    return outputStartPosition;
  }
View Full Code Here

  private FilePosition afterSymbolPosition() {
    return currentPosition();
  }

  private FilePosition currentPosition() {
    return new FilePosition(cssBuilder.getLine(), cssBuilder.getColumn());
  }
View Full Code Here

  private FilePosition currentPosition() {
    return new FilePosition(cssBuilder.getLine(), cssBuilder.getColumn());
  }

  public void append(SourceMapBuilder other) {
    FilePosition offset = afterSymbolPosition();
    cssBuilder.appendAsIs(other.cssBuilder.toString());
    SourceMapGenerator otherGenerator = other.generator;
    generator.offsetAndAppend(otherGenerator, offset);
  }
View Full Code Here

    SourceMapGenerator otherGenerator = other.generator;
    generator.offsetAndAppend(otherGenerator, offset);
  }

  private FilePosition toFilePosition(HiddenTokenAwareTree underlyingStructure) {
    FilePosition result = new FilePosition(underlyingStructure.getLine() - 1, underlyingStructure.getCharPositionInLine());
    return result;
  }
View Full Code Here

public class SourceMapBuilderTest {

  @Test
  public void unknownFilenamesSameContent() throws Exception {
    SourceMapGenerator generator = SourceMapGeneratorFactory.getInstance(SourceMapFormat.V3);
    generator.addMapping(null, "content", "ahoj", new FilePosition(1, 1), new FilePosition(1, 1), new FilePosition(1, 5));
    generator.addMapping(null, "content", "nazdar", new FilePosition(2, 1), new FilePosition(2, 1), new FilePosition(2, 5));
    generator.addMapping(null, "content", "hello", new FilePosition(3, 1), new FilePosition(3, 1), new FilePosition(3, 5));
   
    String map = generateMap(generator);
    assertEquals("{\n\"version\":3,\n\"file\":\"name\",\n\"lineCount\":4,\n\"mappings\":\"A;CACCA,I;CACAC,I;CACAC;\",\n\"sources\":[null],\n\"sourcesContent\":[\"content\"],\n\"names\":[\"ahoj\",\"nazdar\",\"hello\"]\n}\n", map);
    //System.out.println(map);
  }
View Full Code Here

  }

  @Test
  public void unknownFilenamesVariousContent() throws Exception {
    SourceMapGenerator generator = SourceMapGeneratorFactory.getInstance(SourceMapFormat.V3);
    generator.addMapping(null, "content", "ahoj", new FilePosition(1, 1), new FilePosition(1, 1), new FilePosition(1, 5));
    generator.addMapping(null, "content", "nazdar", new FilePosition(2, 1), new FilePosition(2, 1), new FilePosition(2, 5));
    generator.addMapping(null, "different", "hello", new FilePosition(3, 1), new FilePosition(3, 1), new FilePosition(3, 5));
   
    String map = generateMap(generator);
    assertEquals("{\n\"version\":3,\n\"file\":\"name\",\n\"lineCount\":4,\n\"mappings\":\"A;CACCA,I;CACAC,I;CCCAC;\",\n\"sources\":[null,null],\n\"sourcesContent\":[\"content\",\"different\"],\n\"names\":[\"ahoj\",\"nazdar\",\"hello\"]\n}\n", map);
    //System.out.println(map);
  }
View Full Code Here

  }

  @Test
  public void differentFilenamesSameContent() throws Exception {
    SourceMapGenerator generator = SourceMapGeneratorFactory.getInstance(SourceMapFormat.V3);
    generator.addMapping("file 1", "ignore", "ahoj", new FilePosition(1, 1), new FilePosition(1, 1), new FilePosition(1, 5));
    generator.addMapping("file 1", "ignore", "nazdar", new FilePosition(2, 1), new FilePosition(2, 1), new FilePosition(2, 5));
    generator.addMapping("file 2", "ignore", "hello", new FilePosition(3, 1), new FilePosition(3, 1), new FilePosition(3, 5));
   
    String map = generateMap(generator);
    assertEquals("{\n\"version\":3,\n\"file\":\"name\",\n\"lineCount\":4,\n\"mappings\":\"A;CACCA,I;CACAC,I;CCCAC;\",\n\"sources\":[\"file 1\",\"file 2\"],\n\"sourcesContent\":[\"ignore\",\"ignore\"],\n\"names\":[\"ahoj\",\"nazdar\",\"hello\"]\n}\n", map);
    //System.out.println(map);
  }
View Full Code Here

TOP

Related Classes of com.github.sommeri.sourcemap.FilePosition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.