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

Fix ArgumentDeclaration.toString() when no args except rest #145

Merged
merged 2 commits into from
May 28, 2017

Conversation

srawlins
Copy link
Contributor

ArgumentDeclaration.toString() unconditionally puts a comma before the rest argument, even if it is the only argument. For example, with the input:

@mixin box-shadow1($shadows...) {
  -webkit-box-shadow: $shadows;
  box-shadow: $shadows;
}

@mixin box-shadow2($arg1, $shadows...) {
  color: $arg1;
  -webkit-box-shadow: $shadows;
  box-shadow: $shadows;
}

@mixin box-shadow2($arg1, $arg2) {
  color: $arg1;
  -webkit-box-shadow: $arg2;
  box-shadow: $arg2;
}

Given this simple visitor and main:

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() {}

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

  void visitIncludeRule(IncludeRule node) {
    stdout.write('  @include ${node.name}');
    stdout.write(node.arguments);
    stdout.write(';\n');
  }

  void visitMixinRule(MixinRule node) {
    stdout.write('@mixin ${node.name}(');
    stdout.write(node.arguments);
    stdout.write(') {\n  ...\n}\n');
  }

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

We output the following:

$ dart argument_declaration.dart f.scss
@mixin box-shadow1(, shadows...) {
  ...
}
@mixin box-shadow2(arg1, shadows...) {
  ...
}
@mixin box-shadow2(arg1, arg2) {
  ...
}

This PR fixes the output to look like:

$ dart argument_declaration.dart f.scss
@mixin box-shadow1(shadows...) {
  ...
}
@mixin box-shadow2(arg1, shadows...) {
  ...
}
@mixin box-shadow2(arg1, arg2) {
  ...
}

(the variables do not include $, but that's another issue, if it's an issue at all.)

@nex3 nex3 merged commit 2fd9df9 into sass:master May 28, 2017
@srawlins srawlins deleted the rest-to-string branch May 29, 2017 03:02
nex3 pushed a commit that referenced this pull request May 10, 2023
Bumps [grinder](https://github.com/google/grinder.dart) from 0.9.2 to 0.9.3.
- [Release notes](https://github.com/google/grinder.dart/releases)
- [Changelog](https://github.com/google/grinder.dart/blob/master/CHANGELOG.md)
- [Commits](google/grinder.dart@0.9.2...v0.9.3)

---
updated-dependencies:
- dependency-name: grinder
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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