From a0e6b5cdcd65c851b44c3486f28ef269a39026c7 Mon Sep 17 00:00:00 2001 From: Sergey Chikuyonok Date: Thu, 30 Oct 2014 00:30:36 +0300 Subject: [PATCH] Removed all external dependencies --- lib/assets/resources.js | 2 +- lib/assets/tabStops.js | 2 +- lib/resolver/css.js | 2 +- lib/utils/abbreviation.js | 5 +- lib/utils/action.js | 5 +- lib/utils/comments.js | 1 - lib/utils/common.js | 37 +++-- lib/utils/cssSections.js | 30 ++-- lib/utils/editor.js | 5 +- lib/utils/template.js | 9 +- lib/vendor/klass.js | 8 +- package.json | 5 +- test/expandAbbreviations.js | 3 +- test/preferences.js | 13 +- test/preprocessors/basic.less | 95 ----------- test/preprocessors/basic.scss | 80 ---------- .../less/extend/extend-chaining.css | 81 ---------- .../less/extend/extend-chaining.less | 91 ----------- .../less/extend/extend-clearfix.css | 19 --- .../less/extend/extend-clearfix.less | 19 --- .../less/extend/extend-exact.css | 37 ----- .../less/extend/extend-exact.less | 46 ------ .../less/extend/extend-media.css | 24 --- .../less/extend/extend-media.less | 24 --- .../preprocessors/less/extend/extend-nest.css | 57 ------- .../less/extend/extend-nest.less | 65 -------- .../less/extend/extend-selector.css | 80 ---------- .../less/extend/extend-selector.less | 99 ------------ test/preprocessors/less/extend/extend.css | 76 --------- test/preprocessors/less/extend/extend.less | 81 ---------- test/preprocessors/resolver.less | 76 --------- test/preprocessors/resolver.scss | 147 ------------------ test/scss-extend.js | 48 ------ test/scss.js | 103 ------------ test/stubs/editor.js | 13 +- 35 files changed, 72 insertions(+), 1416 deletions(-) delete mode 100644 test/preprocessors/basic.less delete mode 100644 test/preprocessors/basic.scss delete mode 100644 test/preprocessors/less/extend/extend-chaining.css delete mode 100644 test/preprocessors/less/extend/extend-chaining.less delete mode 100644 test/preprocessors/less/extend/extend-clearfix.css delete mode 100644 test/preprocessors/less/extend/extend-clearfix.less delete mode 100644 test/preprocessors/less/extend/extend-exact.css delete mode 100644 test/preprocessors/less/extend/extend-exact.less delete mode 100644 test/preprocessors/less/extend/extend-media.css delete mode 100644 test/preprocessors/less/extend/extend-media.less delete mode 100644 test/preprocessors/less/extend/extend-nest.css delete mode 100644 test/preprocessors/less/extend/extend-nest.less delete mode 100644 test/preprocessors/less/extend/extend-selector.css delete mode 100644 test/preprocessors/less/extend/extend-selector.less delete mode 100644 test/preprocessors/less/extend/extend.css delete mode 100644 test/preprocessors/less/extend/extend.less delete mode 100644 test/preprocessors/resolver.less delete mode 100644 test/preprocessors/resolver.scss delete mode 100644 test/scss-extend.js delete mode 100644 test/scss.js diff --git a/lib/assets/resources.js b/lib/assets/resources.js index f8a4d89d..d714babc 100644 --- a/lib/assets/resources.js +++ b/lib/assets/resources.js @@ -94,7 +94,7 @@ define(function(require, exports, module) { function expandSnippetsDefinition(snippets) { var out = {}; - each(snippets)(function(val, key) { + each(snippets, function(val, key) { var items = key.split('|'); // do not use iterators for better performance for (var i = items.length - 1; i >= 0; i--) { diff --git a/lib/assets/tabStops.js b/lib/assets/tabStops.js index c248265f..d2a5b4c6 100644 --- a/lib/assets/tabStops.js +++ b/lib/assets/tabStops.js @@ -139,7 +139,7 @@ define(function(require, exports, module) { text: buf, tabstops: tabStops.sort(function(a, b) { return a.start - b.start; - }); + }) }; }, diff --git a/lib/resolver/css.js b/lib/resolver/css.js index e57646dd..c6bfff3d 100644 --- a/lib/resolver/css.js +++ b/lib/resolver/css.js @@ -720,7 +720,7 @@ define(function(require, exports, module) { stream.match(/^t|[0-9a-f]+(\.\d+)?/i, true); values.push(stream.current()); } else if (ch == '-') { - if (isValidKeyword(values[values.length - 1] || + if (isValidKeyword(utils.last(values)) || ( stream.start && isNumeric(str.charAt(stream.start - 1)) ) ) { stream.start = stream.pos; diff --git a/lib/utils/abbreviation.js b/lib/utils/abbreviation.js index b8ede89a..557440e7 100644 --- a/lib/utils/abbreviation.js +++ b/lib/utils/abbreviation.js @@ -10,7 +10,6 @@ if (typeof module === 'object' && typeof define !== 'function') { } define(function(require, exports, module) { - var _ = require('lodash'); var elements = require('../assets/elements'); var tabStops = require('../assets/tabStops'); var utils = require('../utils/common'); @@ -77,7 +76,7 @@ define(function(require, exports, module) { */ hasBlockChildren: function(node) { return (this.hasTagsInContent(node) && this.isBlock(node)) - || _.any(node.children, function(child) { + || node.children.some(function(child) { return this.isBlock(child); }, this); }, @@ -91,7 +90,7 @@ define(function(require, exports, module) { * @returns {String */ insertChildContent: function(text, childContent, options) { - options = _.extend({ + options = utils.extend({ keepVariable: true, appendIfNoChild: true }, options || {}); diff --git a/lib/utils/action.js b/lib/utils/action.js index e1bdd0d6..b18d33b8 100644 --- a/lib/utils/action.js +++ b/lib/utils/action.js @@ -9,7 +9,6 @@ if (typeof module === 'object' && typeof define !== 'function') { } define(function(require, exports, module) { - var _ = require('lodash'); var utils = require('./common'); var cssSections = require('./cssSections'); var abbreviationParser = require('../parser/abbreviation'); @@ -165,7 +164,7 @@ define(function(require, exports, module) { var syntax = editor.getSyntax(); if (syntax in allowedSyntaxes) { var content = editor.getContent(); - if (_.isUndefined(pos)) { + if (typeof pos === 'undefined') { pos = editor.getCaretPos(); } @@ -181,7 +180,7 @@ define(function(require, exports, module) { // parse attributes var tagTree = xmlEditTree.parse(startTag.range.substring(content)); if (tagTree) { - contextNode.attributes = _.map(tagTree.getAll(), function(item) { + contextNode.attributes = tagTree.getAll().map(function(item) { return { name: item.name(), value: item.value() diff --git a/lib/utils/comments.js b/lib/utils/comments.js index b7d63d53..8bd51375 100644 --- a/lib/utils/comments.js +++ b/lib/utils/comments.js @@ -9,7 +9,6 @@ if (typeof module === 'object' && typeof define !== 'function') { } define(function(require, exports, module) { - var _ = require('lodash'); var utils = require('./common'); var range = require('../assets/range'); var stringStream = require('../assets/stringStream'); diff --git a/lib/utils/common.js b/lib/utils/common.js index 9f9e5c7d..40750287 100644 --- a/lib/utils/common.js +++ b/lib/utils/common.js @@ -8,7 +8,6 @@ if (typeof module === 'object' && typeof define !== 'function') { } define(function(require, exports, module) { - var _ = require('lodash'); var range = require('../assets/range'); /** @@ -87,7 +86,7 @@ define(function(require, exports, module) { .split(nl); if (removeEmpty) { - lines = _.filter(lines, function(line) { + lines = lines.filter(function(line) { return line.length && !!this.trim(line); }, this); } @@ -116,12 +115,14 @@ define(function(require, exports, module) { * @returns {Array} */ getStringsPads: function(strings) { - var lengths = _.map(strings, function(s) { - return _.isString(s) ? s.length : +s; + var lengths = strings.map(function(s) { + return typeof s === 'string' ? s.length : +s; }); - var max = _.max(lengths); - return _.map(lengths, function(l) { + var max = lengths.reduce(function(prev, cur) { + return typeof prev === 'undefined' ? cur : Math.max(prev, cur); + }); + return lengths.map(function(l) { var pad = max - l; return pad ? this.repeatString(' ', pad) : ''; }, this); @@ -201,7 +202,7 @@ define(function(require, exports, module) { var curSl = sl; matchCount++; var newValue = replace; - if (_.isFunction(replace)) { + if (typeof replace === 'function') { var replaceData = replace(str, symbol, i, matchCount); if (replaceData) { curSl = replaceData[0].length; @@ -269,7 +270,7 @@ define(function(require, exports, module) { base = parseInt(m[2] || 1, 10) - 1; } - if (decrement && total && _.isNumber(value)) { + if (decrement && total && typeof value === 'number') { value = total - value + 1; } @@ -314,7 +315,7 @@ define(function(require, exports, module) { * @returns {String} */ getCaretPlaceholder: function() { - return _.isFunction(caretPlaceholder) + return typeof caretPlaceholder === 'function' ? caretPlaceholder.apply(this, arguments) : caretPlaceholder; }, @@ -382,16 +383,18 @@ define(function(require, exports, module) { * start argument is used */ replaceSubstring: function(str, value, start, end) { - if (_.isObject(start) && 'end' in start) { + if (typeof start === 'object' && 'end' in start) { end = start.end; start = start.start; } - if (_.isString(end)) + if (typeof end === 'string') { end = start + end.length; + } - if (_.isUndefined(end)) + if (typeof end === 'undefined') { end = start; + } if (start < 0 || start > str.length) return str; @@ -409,7 +412,7 @@ define(function(require, exports, module) { replaceWith: function(content, ranges, ch, noRepeat) { if (ranges.length) { var offset = 0, fragments = []; - _.each(ranges, function(r) { + ranges.forEach(function(r) { var repl = noRepeat ? ch : this.repeatString(ch, r[1] - r[0]); fragments.push(content.substring(offset, r[0]), repl); offset = r[1]; @@ -495,7 +498,7 @@ define(function(require, exports, module) { // Handle case when target is a string or something (possible in deep copy) - if (!_.isObject(target) && !_.isFunction(target)) { + if (typeof target !== 'object' && typeof target !== 'function') { target = {}; } @@ -513,13 +516,13 @@ define(function(require, exports, module) { } // Recurse if we're merging plain objects or arrays - if ( copy && ( _.isObject(copy) || (copyIsArray = _.isArray(copy)) ) ) { + if ( copy && ( typeof copy === 'object' || (copyIsArray = Array.isArray(copy)) ) ) { if ( copyIsArray ) { copyIsArray = false; - clone = src && _.isArray(src) ? src : []; + clone = src && Array.isArray(src) ? src : []; } else { - clone = src && _.isObject(src) ? src : {}; + clone = src && typeof src === 'object' ? src : {}; } // Never move original objects, clone them diff --git a/lib/utils/cssSections.js b/lib/utils/cssSections.js index e075306a..dc61f6cf 100644 --- a/lib/utils/cssSections.js +++ b/lib/utils/cssSections.js @@ -5,7 +5,6 @@ if (typeof module === 'object' && typeof define !== 'function') { } define(function(require, exports, module) { - var _ = require('lodash'); var utils = require('./common'); var commentsUtils = require('./comments'); var range = require('../assets/range'); @@ -68,7 +67,7 @@ define(function(require, exports, module) { section = new CSSSection(section); } - var lastChild = _.last(this.children); + var lastChild = utils.last(this.children); if (lastChild) { lastChild.nextSibling = section; section.previousSibling = lastChild; @@ -159,7 +158,7 @@ define(function(require, exports, module) { out.push(this.range); } - _.each(this.children, function(child) { + this.children.forEach(function(child) { out = out.concat(child.allRanges()); }); @@ -177,7 +176,7 @@ define(function(require, exports, module) { stringify: function(indent) { indent = indent || ''; var out = ''; - _.each(this.children, function(item) { + this.children.forEach(function(item) { out += indent + item.name().replace(/\n/g, '\\n') + '\n'; out += item.stringify(indent + '--'); }); @@ -204,7 +203,7 @@ define(function(require, exports, module) { var start = r.start; var out = ''; - _.each(this.children, function(child) { + this.children.forEach(function(child) { out += source.substring(start, child.range.start); start = child.range.end; }); @@ -224,14 +223,15 @@ define(function(require, exports, module) { content = this.sanitize(content); var stream = stringStream(content); var ranges = [], matchedRanges; + var self = this; - var saveRule = _.bind(function(r) { - var selRange = this.extractSelector(content, r.start); + var saveRule = function(r) { + var selRange = self.extractSelector(content, r.start); var rule = range.create2(selRange.start, r.end); rule._selectorEnd = selRange.end; rule._contentStart = r.start; ranges.push(rule); - }, this); + }; var ch; while (ch = stream.next()) { @@ -245,10 +245,10 @@ define(function(require, exports, module) { if (ch == '{') { matchedRanges = this.matchBracesRanges(content, stream.pos - 1); - _.each(matchedRanges, saveRule); + matchedRanges.forEach(saveRule); if (matchedRanges.length) { - stream.pos = _.last(matchedRanges).end; + stream.pos = utils.last(matchedRanges).end; continue; } } @@ -375,15 +375,15 @@ define(function(require, exports, module) { * @return {Range} */ matchEnclosingRule: function(content, pos) { - if (_.isString(content)) { + if (typeof content === 'string') { content = this.findAllRules(content); } - var rules = _.filter(content, function(r) { + var rules = content.filter(function(r) { return r.inside(pos); }); - return _.last(rules); + return utils.last(rules); }, /** @@ -485,7 +485,7 @@ define(function(require, exports, module) { }; var ctx = root; - _.each(rules, function(r) { + rules.forEach(function(r) { ctx = insert(r, ctx); }); @@ -501,7 +501,7 @@ define(function(require, exports, module) { nestedSectionsInRule: function(rule) { var offset = rule.valueRange(true).start; var nestedSections = this.findAllRules(rule.valueRange().substring(rule.source)); - _.each(nestedSections, function(section) { + nestedSections.forEach(function(section) { section.start += offset; section.end += offset; section._selectorEnd += offset; diff --git a/lib/utils/editor.js b/lib/utils/editor.js index 43c366bc..9e4245d2 100644 --- a/lib/utils/editor.js +++ b/lib/utils/editor.js @@ -9,7 +9,6 @@ if (typeof module === 'object' && typeof define !== 'function') { } define(function(require, exports, module) { - var _ = require('lodash'); var utils = require('./common'); var resources = require('../assets/resources'); @@ -90,7 +89,7 @@ define(function(require, exports, module) { * @return {String} */ normalize: function(text, options) { - options = _.extend({ + options = utils.extend({ newline: resources.getNewline(), indentation: resources.getVariable('indentation') }, options); @@ -104,7 +103,7 @@ define(function(require, exports, module) { // normailze indentation if it’s not tabs if (options.indentation !== '\t') { - lines = _.map(lines, function(line) { + lines = lines.map(function(line) { return line.replace(reIndent, indent); }); } diff --git a/lib/utils/template.js b/lib/utils/template.js index b6d4512f..91e61c84 100644 --- a/lib/utils/template.js +++ b/lib/utils/template.js @@ -10,7 +10,6 @@ if (typeof module === 'object' && typeof define !== 'function') { } define(function(require, exports, module) { - var _ = require('lodash'); var stringStream = require('../assets/stringStream'); var utils = require('./common'); @@ -28,7 +27,9 @@ define(function(require, exports, module) { } args.push(utils.trim(stream.current())); - return _.compact(args); + return args.filter(function(a) { + return !!a; + }); } function parseFunctionCall(str) { @@ -59,7 +60,7 @@ define(function(require, exports, module) { return arg.replace(/^(['"])(.+?)\1$/, '$2'); } - if (!_.isNaN(+arg)) { + if (!isNaN(+arg)) { // a number return +arg; } @@ -81,7 +82,7 @@ define(function(require, exports, module) { match = utils.trim(match); var fn = parseFunctionCall(match); if (fn) { - var fnArgs = _.map(fn.args, function(arg) { + var fnArgs = fn.args.map(function(arg) { return evalArg(arg, context); }); return context[fn.name].apply(context, fnArgs); diff --git a/lib/vendor/klass.js b/lib/vendor/klass.js index cc8ceb08..dff75a17 100644 --- a/lib/vendor/klass.js +++ b/lib/vendor/klass.js @@ -5,7 +5,7 @@ if (typeof module === 'object' && typeof define !== 'function') { } define(function(require, exports, module) { - var _ = require('lodash'); + var utils = require('../utils/common'); /** * Shared empty constructor function to aid in prototype-chain creation. @@ -37,7 +37,7 @@ define(function(require, exports, module) { } // Inherit class (static) properties from parent. - _.extend(child, parent); + utils.extend(child, parent); // Set the prototype chain to inherit from `parent`, without calling // `parent`'s constructor function. @@ -47,11 +47,11 @@ define(function(require, exports, module) { // Add prototype properties (instance properties) to the subclass, // if supplied. if (protoProps) - _.extend(child.prototype, protoProps); + utils.extend(child.prototype, protoProps); // Add static properties to the constructor function, if supplied. if (staticProps) - _.extend(child, staticProps); + utils.extend(child, staticProps); // Correctly set child's `prototype.constructor`. child.prototype.constructor = child; diff --git a/package.json b/package.json index a89b24d9..ce0b15cb 100644 --- a/package.json +++ b/package.json @@ -26,10 +26,7 @@ "grunt": "~0.4.1", "mocha": "~1.13.0", "grunt-contrib-requirejs": "~0.4.1", - "grunt-contrib-uglify": "~0.2.4" - }, - "dependencies": { - "lodash": "git://github.com/emmetio/lodash.git", + "grunt-contrib-uglify": "~0.2.4", "requirejs": "~2.1.9" } } diff --git a/test/expandAbbreviations.js b/test/expandAbbreviations.js index 9e78edd1..1fb0744d 100644 --- a/test/expandAbbreviations.js +++ b/test/expandAbbreviations.js @@ -1,4 +1,3 @@ -var _ = require('lodash'); var assert = require('assert'); var editor = require('./stubs/editor'); var parser = require('../lib/parser/abbreviation'); @@ -32,7 +31,7 @@ describe('Abbreviation Expander engine', function() { var caret = utils.getCaretPlaceholder(); function expand(abbr, options) { - options = _.extend({profile: 'plain'}, options || {}); + options = utils.extend({profile: 'plain'}, options || {}); return tabStops.processText(parser.expand(abbr, options), { escape: function(ch) { return ch; diff --git a/test/preferences.js b/test/preferences.js index eac8d313..f556677a 100644 --- a/test/preferences.js +++ b/test/preferences.js @@ -1,8 +1,13 @@ -var _ = require('lodash'); var assert = require('assert'); var prefs = require('../lib/assets/preferences'); describe('Preferences', function() { + function pluck(arr, key) { + return arr.map(function(item) { + return item[key]; + }); + } + it('should work', function() { prefs._startTest(); @@ -21,11 +26,11 @@ describe('Preferences', function() { assert.deepEqual(prefs.get('d'), {p: 1}, 'Successfully set property "d"'); var list = prefs.list(); - assert.deepEqual(_.pluck(list, 'name'), ['a', 'b', 'c', 'd'], 'Listed all properties'); - assert.deepEqual(_.pluck(list, 'value'), [1, 'v1', 'v2', {p: 1}], 'Listed all values'); + assert.deepEqual(pluck(list, 'name'), ['a', 'b', 'c', 'd'], 'Listed all properties'); + assert.deepEqual(pluck(list, 'value'), [1, 'v1', 'v2', {p: 1}], 'Listed all values'); prefs.remove('d'); - assert.deepEqual(_.pluck(prefs.list(), 'name'), ['a', 'b', 'c'], 'Removed property "d"'); + assert.deepEqual(pluck(prefs.list(), 'name'), ['a', 'b', 'c'], 'Removed property "d"'); prefs._stopTest(); }); diff --git a/test/preprocessors/basic.less b/test/preprocessors/basic.less deleted file mode 100644 index c82e9bad..00000000 --- a/test/preprocessors/basic.less +++ /dev/null @@ -1,95 +0,0 @@ -// variables -@nice-blue: #5B83AD; -@light-blue: (@nice-blue + #111); -@fnord: "I am fnord."; - -#header { - color: @light-blue; -} - -.class1 { - @fnord: 1; - one: @fnord; -} - -// mixins -.bordered { - border-top: dotted 1px black; - border-bottom: solid 2px black; -} - -.border-radius (@radius: 5px; @var2: #fc0) { - -moz-border-radius: @radius; - -webkit-border-radius: @radius; - border-radius: @radius; -} - -.wrap () { - text-wrap: wrap; - word-wrap: break-word; -} - -.mixin (@a) when (lightness(@a) >= 50%) { - background-color: black; -} - -#menu a { - color: #111; - .bordered; - padding: 10px; -} - -#header { - .border-radius(4px); - .wrap !important; -} - -// nesting -#header { - color: black; - - .navigation { - font-size: 12px; - } - - .logo { - width: 300px; - &:hover { text-decoration: none } - } -} - -.one { - @media (width: 400px) { - font-size: 1.2em; - @media print and color { - color: blue; - } - } -} - -// extend -div { - background-color: #e0e0e0; -} - -p:extend(div) { - color: #101010; -} - -// namespaces -#bundle { - .button () { - display: block; - } -} - -#header a { - color: orange; - #bundle > .button; -} - -// interpolation -.@{name} { - color: black; - filter: ~"ms:alwaysHasItsOwnSyntax.For.@{what}()"; -} \ No newline at end of file diff --git a/test/preprocessors/basic.scss b/test/preprocessors/basic.scss deleted file mode 100644 index 1b89402f..00000000 --- a/test/preprocessors/basic.scss +++ /dev/null @@ -1,80 +0,0 @@ -@import "rounded-corners", "text-shadow"; -$font-stack: Helvetica, sans-serif; -$primary-color: #333; -$content: "Second content?" !default; - -body { - font: 100% $font-stack; - color: $primary-color; -} - -nav { - font-size: 20px; - - ul { - margin: 0; - padding: 0; - list-style: none; - } -} - -@mixin border-radius($radius) { - -webkit-border-radius: $radius; - -moz-border-radius: $radius; - -ms-border-radius: $radius; - -o-border-radius: $radius; - border-radius: $radius; -} - -.box { - @include border-radius(10px); -} - -message { - border: 1px solid #ccc; - padding: 10px; - color: #333; -} - -.success { - @extend .message; - border-color: green; -} - -article[role="main"] { - float: left; - width: 600px / 960px * 100%; -} - -// comment -a { - font-weight: bold; - text-decoration: none; - &:hover { text-decoration: underline; } - body.firefox & { font-weight: normal; } -} - -// should not be rendered, @extend-only -#context a%extreme { - color: blue; - font-weight: bold; - font-size: 2em; -} - -.notice { - @extend %extreme; -} - -@debug 10em + 12em; - -p { - @if 1 + 1 == 2 { border: 1px solid; } - @if 5 < 3 { border: 2px dotted; } - @if null { border: 3px double; } -} - -@mixin firefox-message($selector) { - body.firefox #{$selector}:before { - content: "Hi, Firefox users!"; - } -} \ No newline at end of file diff --git a/test/preprocessors/less/extend/extend-chaining.css b/test/preprocessors/less/extend/extend-chaining.css deleted file mode 100644 index 820e134f..00000000 --- a/test/preprocessors/less/extend/extend-chaining.css +++ /dev/null @@ -1,81 +0,0 @@ -.a, -.b, -.c { - color: black; -} -.f, -.e, -.d { - color: black; -} -.g.h, -.i.j.h, -.k.j.h { - color: black; -} -.i.j, -.k.j { - color: white; -} -.l, -.m, -.n, -.o, -.p, -.q, -.r, -.s, -.t { - color: black; -} -.u, -.v.u.v { - color: black; -} -.w, -.v.w.v { - color: black; -} -.x, -.y, -.z { - color: x; -} -.y, -.z, -.x { - color: y; -} -.z, -.x, -.y { - color: z; -} -.va, -.vb, -.vc { - color: black; -} -.vb, -.vc { - color: white; -} -@media tv { - .ma, - .mb, - .mc { - color: black; - } - .md, - .ma, - .mb, - .mc { - color: white; - } -} -@media tv and plasma { - .me, - .mf { - background: red; - } -} diff --git a/test/preprocessors/less/extend/extend-chaining.less b/test/preprocessors/less/extend/extend-chaining.less deleted file mode 100644 index aad221ea..00000000 --- a/test/preprocessors/less/extend/extend-chaining.less +++ /dev/null @@ -1,91 +0,0 @@ -//very simple chaining -.a { - color: black; -} -.b:extend(.a) {} -.c:extend(.b) {} - -//very simple chaining, ordering not important - -.d:extend(.e) {} -.e:extend(.f) {} -.f { - color: black; -} - -//extend with all - -.g.h { - color: black; -} -.i.j:extend(.g all) { - color: white; -} -.k:extend(.i all) {} - -//extend multi-chaining - -.l { - color: black; -} -.m:extend(.l){} -.n:extend(.m){} -.o:extend(.n){} -.p:extend(.o){} -.q:extend(.p){} -.r:extend(.q){} -.s:extend(.r){} -.t:extend(.s){} - -// self referencing is ignored - -.u {color: black;} -.v.u.v:extend(.u all){} - -// circular reference because the new extend product will match the existing extend - -.w:extend(.w) {color: black;} -.v.w.v:extend(.w all){} - -// classic circular references - -.x:extend(.z) { - color: x; -} -.y:extend(.x) { - color: y; -} -.z:extend(.y) { - color: z; -} - -//very simple chaining, but with the extend inside the ruleset -.va { - color: black; -} -.vb { - &:extend(.va); - color: white; -} -.vc { - &:extend(.vb); -} - -// media queries - dont extend outside, do extend inside - -@media tv { - .ma:extend(.a,.b,.c,.d,.e,.f,.g,.h,.i,.j,.k,.l,.m,.n,.o,.p,.q,.r,.s,.t,.u,.v,.w,.x,.y,.z,.md) { - color: black; - } - .md { - color: white; - } - @media plasma { - .me, .mf { - &:extend(.mb,.md); - background: red; - } - } -} -.mb:extend(.ma) {}; -.mc:extend(.mb) {}; \ No newline at end of file diff --git a/test/preprocessors/less/extend/extend-clearfix.css b/test/preprocessors/less/extend/extend-clearfix.css deleted file mode 100644 index 966892a2..00000000 --- a/test/preprocessors/less/extend/extend-clearfix.css +++ /dev/null @@ -1,19 +0,0 @@ -.clearfix, -.foo, -.bar { - *zoom: 1; -} -.clearfix:after, -.foo:after, -.bar:after { - content: ''; - display: block; - clear: both; - height: 0; -} -.foo { - color: red; -} -.bar { - color: blue; -} diff --git a/test/preprocessors/less/extend/extend-clearfix.less b/test/preprocessors/less/extend/extend-clearfix.less deleted file mode 100644 index 82445dfa..00000000 --- a/test/preprocessors/less/extend/extend-clearfix.less +++ /dev/null @@ -1,19 +0,0 @@ -.clearfix { - *zoom: 1; - &:after { - content: ''; - display: block; - clear: both; - height: 0; - } -} - -.foo { - &:extend(.clearfix all); - color: red; -} - -.bar { - &:extend(.clearfix all); - color: blue; -} diff --git a/test/preprocessors/less/extend/extend-exact.css b/test/preprocessors/less/extend/extend-exact.css deleted file mode 100644 index beff4133..00000000 --- a/test/preprocessors/less/extend/extend-exact.css +++ /dev/null @@ -1,37 +0,0 @@ -.replace.replace .replace, -.c.replace + .replace .replace, -.replace.replace .c, -.c.replace + .replace .c, -.rep_ace { - prop: copy-paste-replace; -} -.a .b .c { - prop: not_effected; -} -.a, -.effected { - prop: is_effected; -} -.a .b { - prop: not_effected; -} -.a .b.c { - prop: not_effected; -} -.c .b .a, -.a .b .a, -.c .a .a, -.a .a .a, -.c .b .c, -.a .b .c, -.c .a .c, -.a .a .c { - prop: not_effected; -} -.e.e, -.dbl { - prop: extend-double; -} -.e.e:hover { - hover: not-extended; -} diff --git a/test/preprocessors/less/extend/extend-exact.less b/test/preprocessors/less/extend/extend-exact.less deleted file mode 100644 index 41dc4130..00000000 --- a/test/preprocessors/less/extend/extend-exact.less +++ /dev/null @@ -1,46 +0,0 @@ -.replace.replace, -.c.replace + .replace { - .replace, - .c { - prop: copy-paste-replace; - } -} -.rep_ace:extend(.replace.replace .replace) {} - -.a .b .c { - prop: not_effected; -} - -.a { - prop: is_effected; - .b { - prop: not_effected; - } - .b.c { - prop: not_effected; - } -} - -.c, .a { - .b, .a { - .a, .c { - prop: not_effected; - } - } -} - -.effected { - &:extend(.a); - &:extend(.b); - &:extend(.c); -} - -.e { - && { - prop: extend-double; - &:hover { - hover: not-extended; - } - } -} -.dbl:extend(.e.e) {} diff --git a/test/preprocessors/less/extend/extend-media.css b/test/preprocessors/less/extend/extend-media.css deleted file mode 100644 index 23bd7b85..00000000 --- a/test/preprocessors/less/extend/extend-media.css +++ /dev/null @@ -1,24 +0,0 @@ -.ext1 .ext2, -.all .ext2 { - background: black; -} -@media tv { - .ext1 .ext3, - .tv-lowres .ext3, - .all .ext3 { - color: white; - } - .tv-lowres { - background: blue; - } -} -@media tv and hires { - .ext1 .ext4, - .tv-hires .ext4, - .all .ext4 { - color: green; - } - .tv-hires { - background: red; - } -} diff --git a/test/preprocessors/less/extend/extend-media.less b/test/preprocessors/less/extend/extend-media.less deleted file mode 100644 index 1b22c3fa..00000000 --- a/test/preprocessors/less/extend/extend-media.less +++ /dev/null @@ -1,24 +0,0 @@ -.ext1 .ext2 { - background: black; -} - -@media tv { - .ext1 .ext3 { - color: white; - } - .tv-lowres :extend(.ext1 all) { - background: blue; - } - @media hires { - .ext1 .ext4 { - color: green; - } - .tv-hires :extend(.ext1 all) { - background: red; - } - } -} - -.all:extend(.ext1 all) { - -} \ No newline at end of file diff --git a/test/preprocessors/less/extend/extend-nest.css b/test/preprocessors/less/extend/extend-nest.css deleted file mode 100644 index 2c3905d9..00000000 --- a/test/preprocessors/less/extend/extend-nest.css +++ /dev/null @@ -1,57 +0,0 @@ -.sidebar, -.sidebar2, -.type1 .sidebar3, -.type2.sidebar4 { - width: 300px; - background: red; -} -.sidebar .box, -.sidebar2 .box, -.type1 .sidebar3 .box, -.type2.sidebar4 .box { - background: #FFF; - border: 1px solid #000; - margin: 10px 0; -} -.sidebar2 { - background: blue; -} -.type1 .sidebar3 { - background: green; -} -.type2.sidebar4 { - background: red; -} -.button, -.submit { - color: black; -} -.button:hover, -.submit:hover { - color: white; -} -.button2 :hover { - nested: white; -} -.button2 :hover { - notnested: black; -} -.amp-test-h, -.amp-test-f.amp-test-c .amp-test-a.amp-test-d.amp-test-a.amp-test-e + .amp-test-c .amp-test-a.amp-test-d.amp-test-a.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-a.amp-test-d.amp-test-a.amp-test-e + .amp-test-c .amp-test-a.amp-test-d.amp-test-b.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-a.amp-test-d.amp-test-a.amp-test-e + .amp-test-c .amp-test-b.amp-test-d.amp-test-a.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-a.amp-test-d.amp-test-a.amp-test-e + .amp-test-c .amp-test-b.amp-test-d.amp-test-b.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-a.amp-test-d.amp-test-b.amp-test-e + .amp-test-c .amp-test-a.amp-test-d.amp-test-a.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-a.amp-test-d.amp-test-b.amp-test-e + .amp-test-c .amp-test-a.amp-test-d.amp-test-b.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-a.amp-test-d.amp-test-b.amp-test-e + .amp-test-c .amp-test-b.amp-test-d.amp-test-a.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-a.amp-test-d.amp-test-b.amp-test-e + .amp-test-c .amp-test-b.amp-test-d.amp-test-b.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-b.amp-test-d.amp-test-a.amp-test-e + .amp-test-c .amp-test-a.amp-test-d.amp-test-a.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-b.amp-test-d.amp-test-a.amp-test-e + .amp-test-c .amp-test-a.amp-test-d.amp-test-b.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-b.amp-test-d.amp-test-a.amp-test-e + .amp-test-c .amp-test-b.amp-test-d.amp-test-a.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-b.amp-test-d.amp-test-a.amp-test-e + .amp-test-c .amp-test-b.amp-test-d.amp-test-b.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-b.amp-test-d.amp-test-b.amp-test-e + .amp-test-c .amp-test-a.amp-test-d.amp-test-a.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-b.amp-test-d.amp-test-b.amp-test-e + .amp-test-c .amp-test-a.amp-test-d.amp-test-b.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-b.amp-test-d.amp-test-b.amp-test-e + .amp-test-c .amp-test-b.amp-test-d.amp-test-a.amp-test-e.amp-test-g, -.amp-test-f.amp-test-c .amp-test-b.amp-test-d.amp-test-b.amp-test-e + .amp-test-c .amp-test-b.amp-test-d.amp-test-b.amp-test-e.amp-test-g { - test: extended by masses of selectors; -} diff --git a/test/preprocessors/less/extend/extend-nest.less b/test/preprocessors/less/extend/extend-nest.less deleted file mode 100644 index 9d4d27bb..00000000 --- a/test/preprocessors/less/extend/extend-nest.less +++ /dev/null @@ -1,65 +0,0 @@ -.sidebar { - width: 300px; - background: red; - - .box { - background: #FFF; - border: 1px solid #000; - margin: 10px 0; - } -} - -.sidebar2 { - &:extend(.sidebar all); - background: blue; -} - -.type1 { - .sidebar3 { - &:extend(.sidebar all); - background: green; - } -} - -.type2 { - &.sidebar4 { - &:extend(.sidebar all); - background: red; - } -} - -.button { - color: black; - &:hover { - color: white; - } -} -.submit { - &:extend(.button); - &:hover:extend(.button:hover) {} -} - -.nomatch { - &:hover:extend(.button :hover) {} -} - -.button2 { - :hover { - nested: white; - } -} -.button2 :hover { - notnested: black; -} - -.nomatch :extend(.button2:hover) {} - -.amp-test-a, -.amp-test-b { - .amp-test-c &.amp-test-d&.amp-test-e { - .amp-test-f&+&.amp-test-g:extend(.amp-test-h) {} - } -} -.amp-test-h { - test: extended by masses of selectors; -} \ No newline at end of file diff --git a/test/preprocessors/less/extend/extend-selector.css b/test/preprocessors/less/extend/extend-selector.css deleted file mode 100644 index da47254b..00000000 --- a/test/preprocessors/less/extend/extend-selector.css +++ /dev/null @@ -1,80 +0,0 @@ -.error, -.badError { - border: 1px #f00; - background: #fdd; -} -.error.intrusion, -.badError.intrusion { - font-size: 1.3em; - font-weight: bold; -} -.intrusion .error, -.intrusion .badError { - display: none; -} -.badError { - border-width: 3px; -} -.foo .bar, -.foo .baz, -.ext1 .ext2 .bar, -.ext1 .ext2 .baz, -.ext3 .bar, -.ext3 .baz, -.ext4 .bar, -.ext4 .baz { - display: none; -} -div.ext5, -.ext6 > .ext5, -div.ext7, -.ext6 > .ext7 { - width: 100px; -} -.ext, -.a .c, -.b .c { - test: 1; -} -.a, -.b { - test: 2; -} -.a .c, -.b .c { - test: 3; -} -.a .c .d, -.b .c .d { - test: 4; -} -.replace.replace .replace, -.c.replace + .replace .replace, -.replace.replace .c, -.c.replace + .replace .c, -.rep_ace.rep_ace .rep_ace, -.c.rep_ace + .rep_ace .rep_ace, -.rep_ace.rep_ace .c, -.c.rep_ace + .rep_ace .c { - prop: copy-paste-replace; -} -.attributes [data="test"], -.attributes .attributes .attribute-test { - extend: attributes; -} -.attributes [data], -.attributes .attributes .attribute-test2 { - extend: attributes2; -} -.attributes [data="test3"], -.attributes .attributes .attribute-test { - extend: attributes2; -} -.header .header-nav, -.footer .footer-nav { - background: red; -} -.header .header-nav:before, -.footer .footer-nav:before { - background: blue; -} diff --git a/test/preprocessors/less/extend/extend-selector.less b/test/preprocessors/less/extend/extend-selector.less deleted file mode 100644 index c7588ee0..00000000 --- a/test/preprocessors/less/extend/extend-selector.less +++ /dev/null @@ -1,99 +0,0 @@ -.error { - border: 1px #f00; - background: #fdd; -} -.error.intrusion { - font-size: 1.3em; - font-weight: bold; -} -.intrusion .error { - display: none; -} -.badError:extend(.error all) { - border-width: 3px; -} - -.foo .bar, .foo .baz { - display: none; -} - -.ext1 .ext2 - :extend(.foo all) { -} - -.ext3:extend(.foo all), -.ext4:extend(.foo all) { -} - -div.ext5, -.ext6 > .ext5 { - width: 100px; -} - -.should-not-exist-in-output, -.ext7:extend(.ext5 all) { -} - -.ext { - test: 1; -} -// same as -// .a .c:extend(.ext all) -// .b .c:extend(.ext all) -// .a .c .d -// .b .c .d -.a, .b { - test: 2; - .c:extend(.ext all) { - test: 3; - .d { - test: 4; - } - } -} - -.replace.replace, -.c.replace + .replace { - .replace, - .c { - prop: copy-paste-replace; - } -} -.rep_ace:extend(.replace all) {} - -.attributes { - [data="test"] { - extend: attributes; - } - .attribute-test { - &:extend([data="test"] all); - } - [data] { - extend: attributes2; - } - .attribute-test2 { - &:extend([data] all); //you could argue it should match [data="test"]... not for now though... - } - @attr-data: "test3"; - [data=@{attr-data}] { - extend: attributes2; - } - .attribute-test { - &:extend([data="test3"] all); - } -} - -.header { - .header-nav { - background: red; - &:before { - background: blue; - } - } -} - -.footer { - .footer-nav { - &:extend( .header .header-nav all ); - } -} \ No newline at end of file diff --git a/test/preprocessors/less/extend/extend.css b/test/preprocessors/less/extend/extend.css deleted file mode 100644 index 2895641a..00000000 --- a/test/preprocessors/less/extend/extend.css +++ /dev/null @@ -1,76 +0,0 @@ -.error, -.badError { - border: 1px #f00; - background: #fdd; -} -.error.intrusion, -.badError.intrusion { - font-size: 1.3em; - font-weight: bold; -} -.intrusion .error, -.intrusion .badError { - display: none; -} -.badError { - border-width: 3px; -} -.foo .bar, -.foo .baz, -.ext1 .ext2 .bar, -.ext1 .ext2 .baz, -.ext3 .bar, -.ext3 .baz, -.foo .ext3, -.ext4 .bar, -.ext4 .baz, -.foo .ext4 { - display: none; -} -div.ext5, -.ext6 > .ext5, -div.ext7, -.ext6 > .ext7 { - width: 100px; -} -.ext8.ext9, -.fuu { - result: add-foo; -} -.ext8 .ext9, -.ext8 + .ext9, -.ext8 > .ext9, -.buu, -.zap, -.zoo { - result: bar-matched; -} -.ext8.nomatch { - result: none; -} -.ext8 .ext9, -.buu { - result: match-nested-bar; -} -.ext8.ext9, -.fuu { - result: match-nested-foo; -} -.aa, -.cc { - color: black; -} -.aa .dd, -.aa .ee { - background: red; -} -.bb, -.cc, -.ee, -.ff { - background: red; -} -.bb .bb, -.ff .ff { - color: black; -} diff --git a/test/preprocessors/less/extend/extend.less b/test/preprocessors/less/extend/extend.less deleted file mode 100644 index 1db5d431..00000000 --- a/test/preprocessors/less/extend/extend.less +++ /dev/null @@ -1,81 +0,0 @@ -.error { - border: 1px #f00; - background: #fdd; -} -.error.intrusion { - font-size: 1.3em; - font-weight: bold; -} -.intrusion .error { - display: none; -} -.badError { - &:extend(.error all); - border-width: 3px; -} - -.foo .bar, .foo .baz { - display: none; -} - -.ext1 .ext2 { - &:extend(.foo all); -} - -.ext3, -.ext4 { - &:extend(.foo all); - &:extend(.bar all); -} - -div.ext5, -.ext6 > .ext5 { - width: 100px; -} - -.ext7 { - &:extend(.ext5 all); -} - -.ext8.ext9 { - result: add-foo; -} -.ext8 .ext9, -.ext8 + .ext9, -.ext8 > .ext9 { - result: bar-matched; -} -.ext8.nomatch { - result: none; -} -.ext8 { - .ext9 { - result: match-nested-bar; - } -} -.ext8 { - &.ext9 { - result: match-nested-foo; - } -} - -.fuu:extend(.ext8.ext9 all) {} -.buu:extend(.ext8 .ext9 all) {} -.zap:extend(.ext8 + .ext9 all) {} -.zoo:extend(.ext8 > .ext9 all) {} - -.aa { - color: black; - .dd { - background: red; - } -} -.bb { - background: red; - .bb { - color: black; - } -} -.cc:extend(.aa,.bb) {} -.ee:extend(.dd all,.bb) {} -.ff:extend(.dd,.bb all) {} \ No newline at end of file diff --git a/test/preprocessors/resolver.less b/test/preprocessors/resolver.less deleted file mode 100644 index f9da5e61..00000000 --- a/test/preprocessors/resolver.less +++ /dev/null @@ -1,76 +0,0 @@ -// mixins -.bordered { - border-top: dotted 1px black; - border-bottom: solid 2px black; -} - -.border-radius (@radius: 5px; @var2: #fc0) { - -moz-border-radius: @radius; - -webkit-border-radius: @radius; - border-radius: @radius; -} - -.wrap () { - text-wrap: wrap; - word-wrap: break-word; -} - -.mixin (@a) when (lightness(@a) >= 50%) { - background-color: black; -} - -// nesting -#header { - color: black; - - .navigation { - font-size: 12px; - } - - .logo { - width: 300px; - &:hover { text-decoration: none } - } -} - -.one { - @media (width: 400px) { - font-size: 1.2em; - @media print and color { - color: blue; - } - } -} - -// extend -div { - background-color: #e0e0e0; -} - -p:extend(div) { - color: #101010; -} - -.a.b.test, -.test.c { - color: orange; -} - -.test { - &:hover { - color: green; - } -} -.replacement :extend(.test all) {} - -// namespaces -#bundle { - .button () { - display: block; - } -} - -#header a { - color: orange; - #bundle > .button; -} \ No newline at end of file diff --git a/test/preprocessors/resolver.scss b/test/preprocessors/resolver.scss deleted file mode 100644 index 58d9b43d..00000000 --- a/test/preprocessors/resolver.scss +++ /dev/null @@ -1,147 +0,0 @@ -// mixins -@mixin bordered { - border-top: dotted 1px black; - border-bottom: solid 2px black; -} - -@mixin border-radius ($radius: 5px, $var2: #fc0) { - -moz-border-radius: $radius; - -webkit-border-radius: $radius; - border-radius: $radius; -} - -// nesting -#header { - color: black; - - .navigation { - font-size: 12px; - } - - .logo { - width: 300px; - &:hover { text-decoration: none } - } - - // properties stack, shouldn't be nested - font: { - family: Arial; - size: 20px; - weight: bold; - } -} - -.one { - @media (width: 400px) { - font-size: 1.2em; - @media print and (min-width: 100px) { - color: blue; - } - } -} - -// extend -.error { - border: 1px #f00; - background-color: #fdd; -} - -.error.intrusion { - background-image: url("/image/hacked.png"); -} - -.attention { - font-size: 3em; - background-color: #ff0; -} - -// multiple extends -.seriousError { - @extend .error; - @extend .attention; - border-width: 3px; -} - -.seriousError { - @extend .error, .attention; - color: 3px; -} - -@media print { - .seriousError2 { - // shouldn't extend: .error is outside of @media - @extend .error; - border-width: 3px; - } -} - -// chaining extends -.criticalError { - @extend .seriousError; - position: fixed; -} - -// partial selector extend -.hoverlink { - @extend a:hover; -} - -.comment a.user:hover { - font-weight: bold; -} - -// selector sequences -#fake-links .link { - @extend b; -} - -b { - color: blue; - &:hover { - text-decoration: underline; - } -} - -// merging selector sequence -#admin .tabbar i { - font-weight: bold; -} - -#demo .overview .fakelink { - @extend i; -} - -#admin2 d .tabbar2 { - font-weight: bold; -} - -#demo2>.overview2>.fakelink2 { - @extend d; -} - -#admin3 e .tabbar3 { - font-weight: bold; -} - -#demo3 .overview3 .fakelink3 { - @extend e; -} - -#admin .tabbar c { - font-weight: bold; -} - -#admin .overview .fakelink { - @extend c; -} - -// @extend-only selector -#context dd%extreme { - color: blue; - font-weight: bold; - font-size: 2em; -} - -.notice { - @extend %extreme !optional; -} \ No newline at end of file diff --git a/test/scss-extend.js b/test/scss-extend.js deleted file mode 100644 index c278ae11..00000000 --- a/test/scss-extend.js +++ /dev/null @@ -1,48 +0,0 @@ -var fs = require('fs'); -var path = require('path'); -var assert = require('assert'); -var scss = require('../lib/resolver/scss'); -var cssSections = require('../lib/utils/cssSections'); - -describe('SCSS Extend', function() { - var scssFile = fs.readFileSync(path.join(__dirname, 'preprocessors/resolver.scss'), {encoding: 'utf8'}); - it('should work', function() { - var tree = cssSections.sectionTree(scssFile); - var list = scss.resolve(tree, {mock: true}); - var result = [ - ['#header'], - ['#header .navigation'], - ['#header .logo'], - ['#header .logo:hover'], - ['.one'], - ['@media (width: 400px)', '.one'], - ['@media (width: 400px) and print and (min-width: 100px)', '.one'], - ['.error, .seriousError, .criticalError'], - ['.error.intrusion, .intrusion.seriousError, .intrusion.criticalError'], - ['.attention, .seriousError, .criticalError'], - ['.seriousError, .criticalError'], - ['.seriousError, .criticalError'], - ['@media print', '.seriousError2'], - ['.criticalError'], - ['.hoverlink'], - ['.comment a.user:hover, .comment .user.hoverlink'], - ['#fake-links .link'], - ['b, #fake-links .link'], - ['b:hover, #fake-links .link:hover'], - ['#admin .tabbar i, #admin .tabbar #demo .overview .fakelink, #demo .overview #admin .tabbar .fakelink'], - ['#demo .overview .fakelink'], - ['#admin2 d .tabbar2, #admin2 #demo2 > .overview2 > .fakelink2 .tabbar2'], - ['#demo2 > .overview2 > .fakelink2'], - ['#admin3 e .tabbar3, #admin3 #demo3 .overview3 .fakelink3 .tabbar3, #demo3 .overview3 #admin3 .fakelink3 .tabbar3'], - ['#demo3 .overview3 .fakelink3'], - ['#admin .tabbar c, #admin .tabbar .overview .fakelink, #admin .overview .tabbar .fakelink'], - ['#admin .overview .fakelink'], - ['#context dd.notice'], - ['.notice'] - ]; - - result.forEach(function(item, i) { - assert.deepEqual(list[i].path, item); - }); - }); -}); \ No newline at end of file diff --git a/test/scss.js b/test/scss.js deleted file mode 100644 index 3520bee6..00000000 --- a/test/scss.js +++ /dev/null @@ -1,103 +0,0 @@ -var assert = require('assert'); -var parser = require('../lib/parser/css'); -var editTree = require('../lib/editTree/css'); -var cssSections = require('../lib/utils/cssSections'); -var range = require('../lib/assets/range'); -var fs = require('fs'); -var path = require('path'); - -describe('SCSS', function() { - var scssFile = fs.readFileSync(path.join(__dirname, 'preprocessors/basic.scss'), {encoding: 'utf8'}); - - it('should parse basic file', function() { - var tokens = parser.parse(scssFile); - assert(tokens.length > 0); - }); - - it('should build editable tree', function() { - // scan sections and selectors - // var allSections = cssSections.findAllRules(scssFile); - var showContents = function(node) { - console.log('\n%s:', node.name()); - - var output = function(node, indent) { - indent = indent || ' '; - node.list().forEach(function(item) { - if (item.type == 'container') { - console.log('%s%s:', indent, item.name().trim()); - output(item, indent + ' '); - } else { - console.log(indent, item.name().trim(), ': ', item.value()); - } - }); - }; - - output(node); - }; - - var tree, node; - - tree = editTree.parseFromPosition(scssFile, 150); - assert.equal(tree.name(), 'body'); - assert.equal(tree.get(0).name(), 'font'); - assert.equal(tree.get(0).value(), '100% $font-stack'); - assert.equal(tree.get(1).name(), 'color'); - assert.equal(tree.get(1).value(), '$primary-color'); - - tree = editTree.parseFromPosition(scssFile, 208); - assert.equal(tree.name(), 'nav'); - assert.equal(tree.get(0).name(), 'font-size'); - assert.equal(tree.get(0).value(), '20px'); - assert.equal(tree.get(1), undefined); - - tree = editTree.parseFromPosition(scssFile, 234); - assert.equal(tree.name(), 'ul'); - assert.equal(tree.get(0).name(), 'margin'); - assert.equal(tree.get(0).value(), '0'); - assert.equal(tree.get(1).name(), 'padding'); - assert.equal(tree.get(1).value(), '0'); - assert.equal(tree.get(2).name(), 'list-style'); - assert.equal(tree.get(2).value(), 'none'); - - tree = editTree.parseFromPosition(scssFile, 358); - assert.equal(tree.name(), '@mixin border-radius($radius)'); - assert.equal(tree.get(0).name(), '-webkit-border-radius'); - assert.equal(tree.get(0).value(), '$radius'); - - tree = editTree.parseFromPosition(scssFile, 464); - assert.equal(tree.name(), '.box'); - assert.equal(tree.get(0).name(), '@include'); - assert.equal(tree.get(0).value(), 'border-radius(10px)'); - - tree = editTree.parseFromPosition(scssFile, 585); - assert.equal(tree.name(), '.success'); - assert.equal(tree.get(0).name(), '@extend'); - assert.equal(tree.get(0).value(), '.message'); - assert.equal(tree.get(1).name(), 'border-color'); - assert.equal(tree.get(1).value(), 'green'); - - tree = editTree.parseFromPosition(scssFile, 888); - assert.equal(tree.name(), '#context a%extreme'); - assert.equal(tree.get(0).name(), 'color'); - assert.equal(tree.get(0).value(), 'blue'); - assert.equal(tree.get(1).name(), 'font-weight'); - assert.equal(tree.get(1).value(), 'bold'); - assert.equal(tree.get(2).name(), 'font-size'); - assert.equal(tree.get(2).value(), '2em'); - - tree = editTree.parseFromPosition(scssFile, 957); - assert.equal(tree.name(), '.notice'); - assert.equal(tree.get(0).name(), '@extend'); - assert.equal(tree.get(0).value(), '%extreme'); - - tree = editTree.parseFromPosition(scssFile, 1025); - assert.equal(tree.name(), '@if 1 + 1 == 2'); - assert.equal(tree.get(0).name(), 'border'); - assert.equal(tree.get(0).value(), '1px solid'); - - tree = editTree.parseFromPosition(scssFile, 1182); - assert.equal(tree.name(), 'body.firefox #{$selector}:before'); - assert.equal(tree.get(0).name(), 'content'); - assert.equal(tree.get(0).value(), '"Hi, Firefox users!"'); - }); -}); \ No newline at end of file diff --git a/test/stubs/editor.js b/test/stubs/editor.js index 3b0a177b..29d83504 100644 --- a/test/stubs/editor.js +++ b/test/stubs/editor.js @@ -1,7 +1,6 @@ /** * Editor stub for unit testing. Implements {@link IEmmetEditor} interface. */ -var _ = require('lodash'); var path = require('path'); var utils = require('../../lib/utils/common'); var tabStops = require('../../lib/assets/tabStops'); @@ -17,6 +16,10 @@ var profile = null; var promptValue = ''; var filePath = path.join(__dirname, 'index.html'); +function isdef(val) { + return typeof val === 'undefined'; +} + module.exports = { /** @memberOf editorStub */ getSelectionRange: function() { @@ -24,7 +27,7 @@ module.exports = { }, createSelection: function(start, end) { - if (_.isUndefined(end)) + if (!isdef(end)) end = start; selection.start = caret = start; @@ -86,9 +89,9 @@ module.exports = { * @param {Boolean} noIndent Do not auto indent value */ replaceContent: function(value, start, end, noIndent) { - if (_.isUndefined(end)) - end = _.isUndefined(start) ? content.length : start; - if (_.isUndefined(start)) start = 0; + if (!isdef(end)) + end = !isdef(start) ? content.length : start; + if (!isdef(start)) start = 0; // indent new value if (!noIndent) {