From 37c5d92af64540f3771ab18609ce15633d0403bb Mon Sep 17 00:00:00 2001 From: kobezzza Date: Sun, 23 Aug 2015 15:03:54 +0300 Subject: [PATCH] Hotfix --- README.md | 38 +++++++++++++++++++++++--------------- README.ru.md | 38 +++++++++++++++++++++++--------------- dist/file.js | 16 +++++++++++----- dist/parser.js | 20 ++++++++++++++++---- monic.js | 2 +- package.json | 2 +- src/file.js | 12 +++++++++--- src/parser.js | 17 +++++++++++++++-- test/match-01/result.js | 12 ++++++------ test/match-01/test.js | 28 ++++++++++++++-------------- test/match-02/result.js | 3 +++ test/match-02/test.js | 9 +++++++++ 12 files changed, 131 insertions(+), 66 deletions(-) create mode 100644 test/match-02/result.js create mode 100644 test/match-02/test.js diff --git a/README.md b/README.md index c9d9756..3bcc976 100644 --- a/README.md +++ b/README.md @@ -338,35 +338,43 @@ alert('Cool!'); The `#match` provides the most flexible interface to work with conditions. ```js -//#set ie 7 +//#set foo -//#match eq ie 7 -alert('eq ie 7'); +//#match foo +alert('foo'); /*? Or //#end match */ //#endmatch -//#match ne ie 8 -alert('ne ie 8'); +//#unset foo + +//#match foo != +alert('foo !='); +//#endmatch + +//#set ie 7 + +//#match ie = 7 +alert('ie = 7'); //#endmatch -//#match ne ie 7 -alert('ne ie 7'); +//#match ie != 8 +alert('ie != 8'); //#endmatch -//#match gt ie 6 -alert('gt ie 6'); +//#match ie > 6 +alert('ie > 6'); //#endmatch -//#match gte ie 7 -alert('gte ie 7'); +//#match ie >= 7 +alert('ie >= 7'); //#endmatch -//#match lt ie 8 -alert('lt ie 6'); +//#match ie < 8 +alert('ie < 8'); //#endmatch -//#match lte ie 7 -alert('lte ie 7'); +//#match ie <= 7 +alert('ie <= 7'); //#endmatch ``` diff --git a/README.ru.md b/README.ru.md index 1553726..9163840 100644 --- a/README.ru.md +++ b/README.ru.md @@ -336,35 +336,43 @@ alert('Cool!'); Директива `#match` предоставляет самый гибкий интерфейс для работы с условиями. ```js -//#set ie 7 +//#set foo -//#match eq ie 7 -alert('eq ie 7'); +//#match foo +alert('foo'); /*? Можно использовать //#end match */ //#endmatch -//#match ne ie 8 -alert('ne ie 8'); +//#unset foo + +//#match foo != +alert('foo !='); +//#endmatch + +//#set ie 7 + +//#match ie = 7 +alert('ie = 7'); //#endmatch -//#match ne ie 7 -alert('ne ie 7'); +//#match ie != 8 +alert('ie != 8'); //#endmatch -//#match gt ie 6 -alert('gt ie 6'); +//#match ie > 6 +alert('ie > 6'); //#endmatch -//#match gte ie 7 -alert('gte ie 7'); +//#match ie >= 7 +alert('ie >= 7'); //#endmatch -//#match lt ie 8 -alert('lt ie 6'); +//#match ie < 8 +alert('ie < 8'); //#endmatch -//#match lte ie 7 -alert('lte ie 7'); +//#match ie <= 7 +alert('ie <= 7'); //#endmatch ``` diff --git a/dist/file.js b/dist/file.js index fa4081d..2a7502c 100644 --- a/dist/file.js +++ b/dist/file.js @@ -1,11 +1,11 @@ /*! - * Monic v2.3.0 + * Monic v2.3.1 * https://github.com/MonicBuilder/Monic * * Released under the MIT license * https://github.com/MonicBuilder/Monic/blob/master/LICENSE * - * Date: Sun, 23 Aug 2015 10:36:26 GMT + * Date: Sun, 23 Aug 2015 12:03:35 GMT */ 'use strict'; @@ -180,18 +180,24 @@ var FileStructure = (function () { /** * Sets matching * - * @param {string} type - condition type * @param {string} flag - condition + * @param {string} type - condition type * @param {(boolean|string)=} [opt_value] - condition value * @return {!FileStructure} */ - FileStructure.prototype.beginMatch = function beginMatch(type, flag) { + FileStructure.prototype.beginMatch = function beginMatch(flag, type) { var opt_value = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2]; var aliases = { eq: 'if', - ne: 'unless' + ne: 'unless', + '=': 'if', + '!=': 'unless', + '>': 'gt', + '>=': 'gte', + '<': 'lt', + '<=': 'lte' }; var ifBlock = { diff --git a/dist/parser.js b/dist/parser.js index cb15a7f..86eb92a 100644 --- a/dist/parser.js +++ b/dist/parser.js @@ -1,11 +1,11 @@ /*! - * Monic v2.3.0 + * Monic v2.3.1 * https://github.com/MonicBuilder/Monic * * Released under the MIT license * https://github.com/MonicBuilder/Monic/blob/master/LICENSE * - * Date: Sun, 23 Aug 2015 10:36:26 GMT + * Date: Sun, 23 Aug 2015 12:03:35 GMT */ 'use strict'; @@ -537,11 +537,23 @@ var Parser = (function () { Parser.prototype._match = function _match(struct, value) { value = value.trim(); - if (!value) { + var args = value.split(/\s+/); + + switch (args.length) { + case 1: + args.push('eq', true); + break; + + case 2: + args.push(true); + break; + } + + if (!value || args.length !== 3) { throw new SyntaxError('Bad "#match" directive'); } - struct.beginMatch.apply(struct, value.split(/\s+/)); + struct.beginMatch.apply(struct, args); }; /** diff --git a/monic.js b/monic.js index 4c9ab1a..c0c3668 100644 --- a/monic.js +++ b/monic.js @@ -21,7 +21,7 @@ const assign = require('object-assign'); /** @type {!Array} */ -exports.VERSION = [2, 3, 0]; +exports.VERSION = [2, 3, 1]; /** * Builds a file diff --git a/package.json b/package.json index 375cfb7..5723791 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "File builder for JavaScript.", "homepage": "https://github.com/MonicBuilder/Monic", "main": "monic.js", - "version": "2.3.0", + "version": "2.3.1", "license": "MIT", "author": { "name": "kobezzza", diff --git a/src/file.js b/src/file.js index d781ff0..2f55bef 100644 --- a/src/file.js +++ b/src/file.js @@ -139,15 +139,21 @@ export class FileStructure { /** * Sets matching * - * @param {string} type - condition type * @param {string} flag - condition + * @param {string} type - condition type * @param {(boolean|string)=} [opt_value] - condition value * @return {!FileStructure} */ - beginMatch(type, flag, opt_value = true) { + beginMatch(flag, type, opt_value = true) { const aliases = { eq: 'if', - ne: 'unless' + ne: 'unless', + '=': 'if', + '!=': 'unless', + '>': 'gt', + '>=': 'gte', + '<': 'lt', + '<=': 'lte' }; const ifBlock = { diff --git a/src/parser.js b/src/parser.js index 8a345cd..05904ab 100644 --- a/src/parser.js +++ b/src/parser.js @@ -478,11 +478,24 @@ export default class Parser { _match(struct, value) { value = value.trim(); - if (!value) { + const + args = value.split(/\s+/); + + switch (args.length) { + case 1: + args.push('eq', true); + break; + + case 2: + args.push(true); + break; + } + + if (!value || args.length !== 3) { throw new SyntaxError('Bad "#match" directive'); } - struct.beginMatch(...value.split(/\s+/)); + struct.beginMatch(...args); } /** diff --git a/test/match-01/result.js b/test/match-01/result.js index aa5fd25..2c6bc77 100644 --- a/test/match-01/result.js +++ b/test/match-01/result.js @@ -1,12 +1,12 @@ -alert('eq ie 7'); +alert('ie = 7'); -alert('ne ie 8'); +alert('ie != 8'); -alert('gt ie 6'); +alert('ie > 6'); -alert('gte ie 7'); +alert('ie >= 7'); -alert('lt ie 6'); +alert('ie < 8'); -alert('lte ie 7'); +alert('ie <= 7'); diff --git a/test/match-01/test.js b/test/match-01/test.js index 7c6a8dd..66dd6cd 100644 --- a/test/match-01/test.js +++ b/test/match-01/test.js @@ -1,28 +1,28 @@ //#set ie 7 -//#match eq ie 7 -alert('eq ie 7'); +//#match ie = 7 +alert('ie = 7'); //#end match -//#match ne ie 8 -alert('ne ie 8'); +//#match ie != 8 +alert('ie != 8'); //#end match -//#match ne ie 7 -alert('ne ie 7'); +//#match ie != 7 +alert('ie != 7'); //#end match -//#match gt ie 6 -alert('gt ie 6'); +//#match ie > 6 +alert('ie > 6'); //#end match -//#match gte ie 7 -alert('gte ie 7'); +//#match ie >= 7 +alert('ie >= 7'); //#end match -//#match lt ie 8 -alert('lt ie 6'); +//#match ie < 8 +alert('ie < 8'); //#end match -//#match lte ie 7 -alert('lte ie 7'); +//#match ie <= 7 +alert('ie <= 7'); //#end match diff --git a/test/match-02/result.js b/test/match-02/result.js new file mode 100644 index 0000000..1699927 --- /dev/null +++ b/test/match-02/result.js @@ -0,0 +1,3 @@ +alert('ie'); + +alert('ie !='); diff --git a/test/match-02/test.js b/test/match-02/test.js new file mode 100644 index 0000000..115c99d --- /dev/null +++ b/test/match-02/test.js @@ -0,0 +1,9 @@ +//#set ie +//#match ie +alert('ie'); +//#end match + +//#unset ie +//#match ie != +alert('ie !='); +//#end match