Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse declaration children before building its span #149

Merged
merged 1 commit into from
Jun 1, 2017

Conversation

srawlins
Copy link
Contributor

Declarations with children have an incorrect source span. Take the following SCSS and simple visitor:

a {
  padding: {
    left: 2px;
    top: 2px;
  }
  width: 2px;

  pre {
    color: red;
  }
}
import 'dart:io';

import 'lib/src/ast/sass.dart';
import 'lib/src/value.dart';
import 'lib/src/visitor/interface/statement.dart';

void main(List<String> args) {
  var file = args.first;
  var contents = new File(file).readAsStringSync();
  var sassTree = new Stylesheet.parseScss(contents);
  sassTree.accept(new LittleVisitor());
}

class LittleVisitor implements StatementVisitor<Value> {
  LittleVisitor() {}

  // ## Statements

  void visitStylesheet(Stylesheet node) {
    for (var child in node.children) {
      child.accept(this);
    }
  }

  void visitStyleRule(StyleRule node) {
    stdout.write(node.selector);
    stdout.write('{\n');
    for (var child in node.children) {
      child.accept(this);
    }
    stdout.write('}\n');
  }

  void visitDeclaration(Declaration node) {
    stdout.write(node.span.text);
  }
}

This prints:

// BEFORE THIS PATCH
a {
padding: width: 2pxpre {
color: red}
}

// AFTER THIS PATCH
a {
padding: {
    left: 2px;
    top: 2px;
  }
  width: 2pxpre {
color: red}
}

@nex3 nex3 merged commit 7677ab1 into sass:master Jun 1, 2017
@nex3
Copy link
Contributor

nex3 commented Jun 1, 2017

Thanks!

nex3 pushed a commit that referenced this pull request May 10, 2023
jgerigmeyer added a commit to oddbird/dart-sass that referenced this pull request May 16, 2023
* main: (162 commits)
  Move source and test files to namespaced subdirectories
  Update Dart Sass version and release
  Update Dart Sass version and release
  Update Dart Sass version and release
  Update Dart Sass version and release
  Update Dart Sass version and release
  Update Dart Sass version and release
  Revert "Remove workaround for dart-lang/setup-dart#59 (sass#151)" (sass#153)
  Update Dart Sass version and release
  Update Dart Sass version and release
  Remove workaround for dart-lang/setup-dart#59 (sass#151)
  Update Dart Sass version and release
  Update Dart Sass version and release
  Fix qemu releases (sass#149)
  Update Dart Sass version and release
  Bump sass_api from 4.2.1 to 5.0.0 (sass#143)
  Bump meta from 1.8.0 to 1.9.0 (sass#144)
  Bump grinder from 0.9.2 to 0.9.3 (sass#145)
  Add missing setup-dart step in qemu release (sass#147)
  Use buf instead of protoc to compile protobufs (sass#146)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants