From 81cb2db2f6325d50bef27c9c3da508af34a07466 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Fri, 24 Nov 2017 14:37:29 -0800 Subject: [PATCH 1/6] Bump version for release. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6bf5523..45f5df3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "css-property-parser", - "version": "1.0.4", + "version": "1.0.5", "description": "Validate css properties and expand shorthand css properties", "keywords": [ "css" From ff4b706371ab3f2313c8f99b2834fb3034f54be0 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Wed, 28 Feb 2018 04:44:53 -0800 Subject: [PATCH 2/6] Use path.join instead of string joins for path construction. Move dynamic requires to boot time. Move formatted-data to the src directory. --- .gitignore | 2 +- package.json | 2 +- src/constants/paths.js | 16 +++++----- src/expandShorthandProperty.js | 7 +++-- .../NearleyGrammarFormatter.js | 5 +-- src/getShorthandComputedProperties.js | 2 +- src/getShorthandsForProperty.js | 4 +-- src/initialValueMap.js | 2 +- src/isShorthandProperty.js | 2 +- src/isValidDeclaration.js | 5 +-- src/scripts/extractProperties.js | 3 +- src/scripts/formatData.js | 10 +++--- src/scripts/formatFormalSyntaxes.js | 10 +++--- src/scripts/formatGrammars.js | 31 ++++++++++--------- src/scripts/updateBasicDataUnits.js | 3 +- test/InitialValuesTest.js | 2 +- .../formatters/NearleyGrammarFormatterTest.js | 7 +++-- updateCSSData.sh | 4 +-- 18 files changed, 64 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index bc21573..70b5cb7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ node_modules .vscode # ignore generated grammars -formatted-data +src/formatted-data src/grammars/generated diff --git a/package.json b/package.json index 45f5df3..735ea04 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "prepublish": "npm start", "test": "./node_modules/.bin/mocha --reporter spec --recursive", "start": "./updateCSSData.sh", - "clean": "rm -rf src/grammars/generated", + "clean": "rm -rf src/formatted-data src/grammars/generated", "benchmark": "node test/benchmark.js", "doctoc": "node ./node_modules/doctoc/doctoc.js README.md", "lint": "node node_modules/eslint/bin/eslint.js src/", diff --git a/src/constants/paths.js b/src/constants/paths.js index 2ad87c6..fbc368b 100644 --- a/src/constants/paths.js +++ b/src/constants/paths.js @@ -1,12 +1,12 @@ const path = require('path'); module.exports = { - JSON_GRAMMAR_PATH: path.join(__dirname, '/../grammars/json/'), - NEARLEY_PROPERTY_GRAMMAR_PATH: path.join(__dirname, '/../grammars/nearley/properties/'), - GENERATED_JSON_GRAMMAR_PATH: path.join(__dirname, '/../grammars/generated/json/'), - GENERATED_NEARLEY_GRAMMAR_PATH: path.join(__dirname, '/../grammars/generated/nearley/'), - GENERATED_JS_GRAMMAR_PATH: path.join(__dirname, '/../grammars/generated/js/'), - FORMATTED_DATA_PATH: path.join(__dirname, '/../../formatted-data/'), - FORMAL_SYNTAX_GRAMMAR_PATH: path.join(__dirname, '/../grammars/'), - NEARLEY_BIN_ROOT: path.join(__dirname, '/../../node_modules/nearley/bin/'), + JSON_GRAMMAR_PATH: path.join(__dirname, '..', 'grammars', 'json'), + NEARLEY_PROPERTY_GRAMMAR_PATH: path.join(__dirname, '..', 'grammars', 'nearley', 'properties'), + GENERATED_JSON_GRAMMAR_PATH: path.join(__dirname, '..', 'grammars', 'generated', 'json'), + GENERATED_NEARLEY_GRAMMAR_PATH: path.join(__dirname, '..', 'grammars', 'generated', 'nearley'), + GENERATED_JS_GRAMMAR_PATH: path.join(__dirname, '..', 'grammars', 'generated', 'js'), + FORMATTED_DATA_PATH: path.join(__dirname, '..', 'formatted-data'), + FORMAL_SYNTAX_GRAMMAR_PATH: path.join(__dirname, '..', 'grammars'), + NEARLEY_BIN_ROOT: path.join(__dirname, '..', '..', 'node_modules', 'nearley', 'bin'), }; diff --git a/src/expandShorthandProperty.js b/src/expandShorthandProperty.js index 83fcc3d..3946a89 100644 --- a/src/expandShorthandProperty.js +++ b/src/expandShorthandProperty.js @@ -1,8 +1,8 @@ const nearley = require('nearley'); -const properties = require('../formatted-data/properties.json'); +const properties = require('./formatted-data/properties.json'); const isShorthandProperty = require('./isShorthandProperty'); const getShorthandComputedProperties = require('./getShorthandComputedProperties'); -const shorthandProperties = require('../formatted-data/shorthand-properties.json'); +const shorthandProperties = require('./formatted-data/shorthand-properties.json'); const CSS_CONSTANTS = require('./constants/css'); const { CLASSIFICATIONS } = require('./constants/shorthandProperties'); const LocationIndexTracker = require('./utils/LocationIndexTracker'); @@ -18,6 +18,7 @@ const { UnorderedOptionalListPropertyFormatter, } = require('./formatters/shorthandPropertyTypeFormatters'); const { initialValue, initialValues } = require('./initialValueMap'); +const grammars = require('./grammars/generated'); const shorthandPropertyTypeToActionDictionaryFactoryMap = { [CLASSIFICATIONS.TRBL]: TrblPropertyFormatter, @@ -88,7 +89,7 @@ module.exports = function expandShorthandProperty(propertyName, } // get the compiled grammar file for this property - const grammar = require('./grammars/generated')[propertyName]; + const grammar = grammars[propertyName]; // remove any block style comments and extra whitespace const formattedPropertyValue = propertyValue.replace(R_BLOCK_COMMENT, ' ').replace(/\s+/g, ' ').trim(); let parser; diff --git a/src/formatters/grammarFormatters/NearleyGrammarFormatter.js b/src/formatters/grammarFormatters/NearleyGrammarFormatter.js index 19d3404..6171f13 100644 --- a/src/formatters/grammarFormatters/NearleyGrammarFormatter.js +++ b/src/formatters/grammarFormatters/NearleyGrammarFormatter.js @@ -1,5 +1,6 @@ const CaseConverterUtils = require('../../utils/CaseConverterUtils'); const fs = require('fs-extra'); +const path = require('path'); const PATHS = require('../../constants/paths'); const GRAMMAR_CONSTANTS = require('../../constants/grammars'); const shorthandIdentToLongHandPropertyMap = require('../../constants/shorthandIdentToLonghandPropertyMap.json'); @@ -36,7 +37,7 @@ module.exports = class NearleyGrammarFormatter { ._getGrammarsToResolve(jsonGrammar) .map(fileToResolve => [ fileToResolve, - fs.readJsonSync(`${PATHS.GENERATED_JSON_GRAMMAR_PATH}${fileToResolve}.json`), + fs.readJsonSync(path.join(PATHS.GENERATED_JSON_GRAMMAR_PATH, `${fileToResolve}.json`)), ]) .filter(([, json]) => NearleyGrammarFormatter._isGrammarValid(json)) .map(([grammarName, jsonGrammar]) => ( @@ -122,7 +123,7 @@ module.exports = class NearleyGrammarFormatter { return [...new Set(resolutions.concat( ...resolutions - .map(file => fs.readJsonSync(`${PATHS.GENERATED_JSON_GRAMMAR_PATH}${file}.json`)) + .map(file => fs.readJsonSync(path.join(PATHS.GENERATED_JSON_GRAMMAR_PATH, `${file}.json`))) .map(grammar => NearleyGrammarFormatter._getGrammarsToResolve(grammar, resolved.concat(resolutions)))))]; } diff --git a/src/getShorthandComputedProperties.js b/src/getShorthandComputedProperties.js index 3164609..890b208 100644 --- a/src/getShorthandComputedProperties.js +++ b/src/getShorthandComputedProperties.js @@ -1,4 +1,4 @@ -const properties = require('../formatted-data/properties.json'); +const properties = require('./formatted-data/properties.json'); /** * Given a shorthand property, returns an array of the computed properties for that shorthand property. If given diff --git a/src/getShorthandsForProperty.js b/src/getShorthandsForProperty.js index 50ebbb4..eabad37 100644 --- a/src/getShorthandsForProperty.js +++ b/src/getShorthandsForProperty.js @@ -1,5 +1,5 @@ -const shortHandProperties = require('../formatted-data/shorthand-properties.json'); -const properties = require('../formatted-data/properties.json'); +const shortHandProperties = require('./formatted-data/shorthand-properties.json'); +const properties = require('./formatted-data/properties.json'); /** * @type {Object} diff --git a/src/initialValueMap.js b/src/initialValueMap.js index c661f48..ee1a982 100644 --- a/src/initialValueMap.js +++ b/src/initialValueMap.js @@ -1,4 +1,4 @@ -const properties = require('../formatted-data/properties.json'); +const properties = require('./formatted-data/properties.json'); const getShorthandComputedProperties = require('./getShorthandComputedProperties'); const isShorthandProperty = require('./isShorthandProperty'); diff --git a/src/isShorthandProperty.js b/src/isShorthandProperty.js index d7c93f3..4389f3d 100644 --- a/src/isShorthandProperty.js +++ b/src/isShorthandProperty.js @@ -1,4 +1,4 @@ -const shortHandProperties = require('../formatted-data/shorthand-properties.json'); +const shortHandProperties = require('./formatted-data/shorthand-properties.json'); /** * Checks if a given property is a shorthand property diff --git a/src/isValidDeclaration.js b/src/isValidDeclaration.js index c9ac2b9..337af37 100644 --- a/src/isValidDeclaration.js +++ b/src/isValidDeclaration.js @@ -1,6 +1,7 @@ const nearley = require('nearley'); -const properties = require('../formatted-data/properties.json'); +const properties = require('./formatted-data/properties.json'); const { CSS } = require('./constants'); +const grammars = require('./grammars/generated'); /** * Checks if the given property, value pair is valid. @@ -16,7 +17,7 @@ module.exports = function isValidDeclaration(property, value) { return true; } - const propertyGrammar = require('./grammars/generated')[property]; + const propertyGrammar = grammars[property]; try { const parser = new nearley.Parser(nearley.Grammar.fromCompiled(propertyGrammar)).feed(value); diff --git a/src/scripts/extractProperties.js b/src/scripts/extractProperties.js index 79fb0f2..5c5ab6e 100644 --- a/src/scripts/extractProperties.js +++ b/src/scripts/extractProperties.js @@ -3,11 +3,12 @@ * Writes the formatted data to FORMATTED_DATA_PATH. */ const fs = require('fs-extra'); +const path = require('path'); const { css: { properties } } = require('mdn-data'); const PATHS = require('../constants/paths'); const ALL_PROPERTIES_DATA_FILE_NAME = 'properties.json'; -const OUTPUT_FILE = `${PATHS.FORMATTED_DATA_PATH}${ALL_PROPERTIES_DATA_FILE_NAME}`; +const OUTPUT_FILE = path.join(PATHS.FORMATTED_DATA_PATH, ALL_PROPERTIES_DATA_FILE_NAME); fs.writeJson(OUTPUT_FILE, properties, { spaces: 2 }) .then(() => ( console.log(`Successfully extracted properties to ${OUTPUT_FILE}`) diff --git a/src/scripts/formatData.js b/src/scripts/formatData.js index fe56ad3..0aa3213 100755 --- a/src/scripts/formatData.js +++ b/src/scripts/formatData.js @@ -3,6 +3,7 @@ * Writes the formatted data to FORMATTED_DATA_PATH. */ const fs = require('fs-extra'); +const path = require('path'); const { css: { properties } } = require('mdn-data'); const ShorthandPropertyClassifierUtils = require('../utils/ShorthandPropertyClassifierUtils'); const PATHS = require('../constants/paths'); @@ -21,7 +22,8 @@ const formattedData = Object.entries(properties) // reduce it down to an object again so we can write it to a file .reduce((propertyMap, [property, data]) => Object.assign({ [property]: data }, propertyMap), {}); -fs.writeJson(`${PATHS.FORMATTED_DATA_PATH}${SHORTHAND_FORMATTED_DATA_FILE_NAME}`, formattedData, { spaces: 2 }) - .then(() => ( - console.log(`Successfully formatted data to ${PATHS.FORMATTED_DATA_PATH}${SHORTHAND_FORMATTED_DATA_FILE_NAME}`) - )); +fs.writeJson(path.join(PATHS.FORMATTED_DATA_PATH, SHORTHAND_FORMATTED_DATA_FILE_NAME), formattedData, { spaces: 2 }) + .then(() => { + const fdPath = path.join(PATHS.FORMATTED_DATA_PATH, SHORTHAND_FORMATTED_DATA_FILE_NAME); + console.log(`Successfully formatted data to ${fdPath}`); + }); diff --git a/src/scripts/formatFormalSyntaxes.js b/src/scripts/formatFormalSyntaxes.js index cc21c81..3bef945 100644 --- a/src/scripts/formatFormalSyntaxes.js +++ b/src/scripts/formatFormalSyntaxes.js @@ -2,6 +2,7 @@ * Format each formal syntax into a json grammar */ const fs = require('fs-extra'); +const path = require('path'); const { css: { properties, syntaxes } } = require('mdn-data'); const { PATHS, SYNTAX_OVERRIDES } = require('../constants/index'); const JsonGrammarFormatter = require('../formatters/grammarFormatters/JsonGrammarFormatter'); @@ -30,18 +31,19 @@ const syntaxesSyntaxMap = Object.entries(syntaxes) const propertySyntaxMap = Object.entries(properties).reduce((syntaxMap, [propertyName, { syntax }]) => ( Object.assign({ [propertyName]: syntax }, syntaxMap) ), syntaxesSyntaxMap); -const overridenPropertySyntaxMap = Object.assign(propertySyntaxMap, SYNTAX_OVERRIDES); +const overriddenPropertySyntaxMap = Object.assign(propertySyntaxMap, SYNTAX_OVERRIDES); // make the json grammar directory if needed if (!fs.existsSync(PATHS.GENERATED_JSON_GRAMMAR_PATH)) { fs.mkdirSync(PATHS.GENERATED_JSON_GRAMMAR_PATH); } -Object.entries(overridenPropertySyntaxMap) +Object.entries(overriddenPropertySyntaxMap) // filter out any entries that we need to do manually .filter(([grammarName]) => !manualSyntaxes.includes(grammarName)) .forEach(([grammarName, formalSyntax]) => { - console.log(`creating ${PATHS.GENERATED_JSON_GRAMMAR_PATH}${grammarName}.json`); + const filename = path.join(PATHS.GENERATED_JSON_GRAMMAR_PATH, `${grammarName}.json`); + console.log(`creating ${filename}`); const jsonGrammar = JsonGrammarFormatter.format(formalSyntax); - fs.writeJson(`${PATHS.GENERATED_JSON_GRAMMAR_PATH}${grammarName}.json`, jsonGrammar, { spaces: 2 }); + fs.writeJson(filename, jsonGrammar, { spaces: 2 }); }); diff --git a/src/scripts/formatGrammars.js b/src/scripts/formatGrammars.js index 347571f..a725a1e 100644 --- a/src/scripts/formatGrammars.js +++ b/src/scripts/formatGrammars.js @@ -24,20 +24,22 @@ if (!fs.existsSync(PATHS.GENERATED_JS_GRAMMAR_PATH)) { } // move manual json grammars into generated folder for grammar resolution -fs.readdirSync(`${PATHS.JSON_GRAMMAR_PATH}`) - .forEach(fileName => ( - fs.copySync(`${PATHS.JSON_GRAMMAR_PATH}${fileName}`, `${PATHS.GENERATED_JSON_GRAMMAR_PATH}${fileName}`)) - ); +fs.readdirSync(PATHS.JSON_GRAMMAR_PATH) + .forEach((fileName) => { + const fullSrc = path.join(PATHS.JSON_GRAMMAR_PATH, fileName); + const fullDest = path.join(PATHS.GENERATED_JSON_GRAMMAR_PATH, fileName); + fs.copySync(fullSrc, fullDest); + }); // read each json grammar and format it into an nearley grammar fs.readdirSync(PATHS.GENERATED_JSON_GRAMMAR_PATH) - .map(fileName => [fileName, fs.readJsonSync(`${PATHS.GENERATED_JSON_GRAMMAR_PATH}${fileName}`)]) + .map(fileName => [fileName, fs.readJsonSync(path.join(PATHS.GENERATED_JSON_GRAMMAR_PATH, fileName))]) .forEach(([fileName, jsonGrammar]) => { console.log(`creating ${fileName}`); const grammarName = fileName.replace('.json', ''); const nearleyGrammar = NearleyGrammarFormatter.format(jsonGrammar, grammarName); - const fileToWrite = `${PATHS.GENERATED_NEARLEY_GRAMMAR_PATH}${fileName.replace('.json', `.${GRAMMAR_CONSTANTS.GRAMMAR_FILE_EXTENSION}`)}`; + const fileToWrite = path.join(PATHS.GENERATED_NEARLEY_GRAMMAR_PATH, fileName.replace('.json', `.${GRAMMAR_CONSTANTS.GRAMMAR_FILE_EXTENSION}`)); fs.createFileSync(fileToWrite); fs.writeFileSync(fileToWrite, nearleyGrammar); @@ -45,12 +47,11 @@ fs.readdirSync(PATHS.GENERATED_JSON_GRAMMAR_PATH) // copy over overridden grammars fs.readdirSync(PATHS.NEARLEY_PROPERTY_GRAMMAR_PATH) - .forEach(fileName => ( - fs.copySync( - `${PATHS.NEARLEY_PROPERTY_GRAMMAR_PATH}${fileName}`, - `${PATHS.GENERATED_NEARLEY_GRAMMAR_PATH}${fileName}` - ) - )); + .forEach((fileName) => { + const fullSrc = path.join(PATHS.NEARLEY_PROPERTY_GRAMMAR_PATH, fileName); + const fullDest = path.join(PATHS.GENERATED_NEARLEY_GRAMMAR_PATH, fileName); + fs.copySync(fullSrc, fullDest); + }); console.log('...Successfully created nearley grammars...'); @@ -65,19 +66,19 @@ const compilationCommands = fs.readdirSync(PATHS.GENERATED_NEARLEY_GRAMMAR_PATH) .map((fileName) => { const propName = fileName.replace(`.${GRAMMAR_CONSTANTS.GRAMMAR_FILE_EXTENSION}`, ''); const jsFileName = `${propName}.${JAVASCRIPT_FILE_EXTENSION}`; - const nearleyFilePath = JSON.stringify(`${PATHS.GENERATED_NEARLEY_GRAMMAR_PATH}${fileName}`); + const nearleyFilePath = JSON.stringify(path.join(PATHS.GENERATED_NEARLEY_GRAMMAR_PATH, fileName)); const jsFilePath = JSON.stringify( path.join(PATHS.GENERATED_JS_GRAMMAR_PATH, jsFileName) ); jsModules.push(` '${propName}': require('./js/${jsFileName}')`); - return `node ${PATHS.NEARLEY_BIN_ROOT}${NEARLEY_COMPILER_FILE_NAME} ${nearleyFilePath} > ${jsFilePath}`; + return `node ${path.join(PATHS.NEARLEY_BIN_ROOT, NEARLEY_COMPILER_FILE_NAME)} ${nearleyFilePath} > ${jsFilePath}`; }); const jsExportsFile = `module.exports = {\n${jsModules.join(',\n')}\n}`; -fs.writeFileSync(path.join(PATHS.GENERATED_JS_GRAMMAR_PATH, '../index.js'), jsExportsFile); +fs.writeFileSync(path.resolve(PATHS.GENERATED_JS_GRAMMAR_PATH, '..', 'index.js'), jsExportsFile); compilationQueue.push(compilationCommands, (err) => { if (err) { diff --git a/src/scripts/updateBasicDataUnits.js b/src/scripts/updateBasicDataUnits.js index 4586204..2a4b8e3 100644 --- a/src/scripts/updateBasicDataUnits.js +++ b/src/scripts/updateBasicDataUnits.js @@ -5,6 +5,7 @@ */ const { css: { units } } = require('mdn-data'); const fs = require('fs-extra'); +const path = require('path'); const PATHS = require('../constants/paths'); const GRAMMAR_CONSTANTS = require('../constants/grammars'); @@ -28,7 +29,7 @@ const unitToTypesMap = Object.entries(units).reduce((unitMap, [unit, { groups }] Promise.all( Object.entries(unitToTypesMap).map(([fileName, unitList]) => ( - fs.writeJson(`${PATHS.GENERATED_JSON_GRAMMAR_PATH}${fileName}.json`, [ + fs.writeJson(path.join(PATHS.GENERATED_JSON_GRAMMAR_PATH, `${fileName}.json`), [ [GRAMMAR_CONSTANTS.BASE_GRAMMAR_RULE_NAME, `( ${unitList.map(unit => `"${unit}"`).join(' | ')} )`], ], { spaces: 2 }) ))) diff --git a/test/InitialValuesTest.js b/test/InitialValuesTest.js index cca2d02..e043724 100644 --- a/test/InitialValuesTest.js +++ b/test/InitialValuesTest.js @@ -1,5 +1,5 @@ const { assert } = require('chai'); -const properties = require('../formatted-data/properties.json'); +const properties = require('../src/formatted-data/properties.json'); const { initialValue, initialValues, diff --git a/test/formatters/NearleyGrammarFormatterTest.js b/test/formatters/NearleyGrammarFormatterTest.js index 7dd5da1..5f3d41e 100644 --- a/test/formatters/NearleyGrammarFormatterTest.js +++ b/test/formatters/NearleyGrammarFormatterTest.js @@ -1,5 +1,6 @@ const sinon = require('sinon'); const fs = require('fs-extra'); +const path = require('path'); const { assert } = require('chai'); const PATHS = require('../../src/constants/paths'); const GRAMMAR_CONSTANTS = require('../../src/constants/grammars'); @@ -58,17 +59,17 @@ describe('NearleyGrammarFormatter#format', function () { describe('recursive cases', function () { it('should handle deeply recursive cases', function () { sandbox.stub(fs, 'readJsonSync') - .withArgs(`${PATHS.GENERATED_JSON_GRAMMAR_PATH}ra.json`) + .withArgs(path.join(PATHS.GENERATED_JSON_GRAMMAR_PATH, 'ra.json')) .returns([ [GRAMMAR_CONSTANTS.BASE_GRAMMAR_RULE_NAME, ''], [''], ]) - .withArgs(`${PATHS.GENERATED_JSON_GRAMMAR_PATH}rb.json`) + .withArgs(path.join(PATHS.GENERATED_JSON_GRAMMAR_PATH, 'rb.json')) .returns([ [GRAMMAR_CONSTANTS.BASE_GRAMMAR_RULE_NAME, ''], [''], ]) - .withArgs(`${PATHS.GENERATED_JSON_GRAMMAR_PATH}rc.json`) + .withArgs(path.join(PATHS.GENERATED_JSON_GRAMMAR_PATH, 'rc.json')) .returns([ [GRAMMAR_CONSTANTS.BASE_GRAMMAR_RULE_NAME, '"d"'], ]); diff --git a/updateCSSData.sh b/updateCSSData.sh index 56867f1..0e5e1d2 100755 --- a/updateCSSData.sh +++ b/updateCSSData.sh @@ -13,8 +13,8 @@ function realpath() echo "$dir$base" } cd "$(dirname "$(realpath "$0")")"; -rm -rf formatted-data src/grammars/generated/json -mkdir -p formatted-data src/grammars/generated/json +rm -rf src/formatted-data src/grammars/generated/json +mkdir -p src/formatted-data src/grammars/generated/json node ./node_modules/nearley/bin/nearleyc.js ./src/grammars/nearley/formalSyntax.ne > ./src/grammars/js/formalSyntax.js || exit 1 node ./src/scripts/updateBasicDataUnits.js || exit 1 node ./src/scripts/formatData.js || exit 1 From 560b2368f6976b3669f504bab8bdde80445a339b Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Wed, 28 Feb 2018 05:05:22 -0800 Subject: [PATCH 3/6] Don't create filenames containing an asterisk. Fixes #21. --- src/scripts/formatFormalSyntaxes.js | 3 ++- src/scripts/formatGrammars.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/scripts/formatFormalSyntaxes.js b/src/scripts/formatFormalSyntaxes.js index 3bef945..8f2c741 100644 --- a/src/scripts/formatFormalSyntaxes.js +++ b/src/scripts/formatFormalSyntaxes.js @@ -42,7 +42,8 @@ Object.entries(overriddenPropertySyntaxMap) // filter out any entries that we need to do manually .filter(([grammarName]) => !manualSyntaxes.includes(grammarName)) .forEach(([grammarName, formalSyntax]) => { - const filename = path.join(PATHS.GENERATED_JSON_GRAMMAR_PATH, `${grammarName}.json`); + const safeName = grammarName.replace('*', 'STAR'); + const filename = path.join(PATHS.GENERATED_JSON_GRAMMAR_PATH, `${safeName}.json`); console.log(`creating ${filename}`); const jsonGrammar = JsonGrammarFormatter.format(formalSyntax); fs.writeJson(filename, jsonGrammar, { spaces: 2 }); diff --git a/src/scripts/formatGrammars.js b/src/scripts/formatGrammars.js index a725a1e..d34ac03 100644 --- a/src/scripts/formatGrammars.js +++ b/src/scripts/formatGrammars.js @@ -65,8 +65,9 @@ const jsModules = []; const compilationCommands = fs.readdirSync(PATHS.GENERATED_NEARLEY_GRAMMAR_PATH) .map((fileName) => { const propName = fileName.replace(`.${GRAMMAR_CONSTANTS.GRAMMAR_FILE_EXTENSION}`, ''); - const jsFileName = `${propName}.${JAVASCRIPT_FILE_EXTENSION}`; - const nearleyFilePath = JSON.stringify(path.join(PATHS.GENERATED_NEARLEY_GRAMMAR_PATH, fileName)); + const safeFileName = propName.replace('*', 'STAR'); + const jsFileName = `${safeFileName}.${JAVASCRIPT_FILE_EXTENSION}`; + const nearleyFilePath = JSON.stringify(path.join(PATHS.GENERATED_NEARLEY_GRAMMAR_PATH, fileName.replace('*', 'STAR'))); const jsFilePath = JSON.stringify( path.join(PATHS.GENERATED_JS_GRAMMAR_PATH, jsFileName) ); From bd1a0ddaffa2c5acc64c5b919433ff5c298fe7d7 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Wed, 28 Feb 2018 05:06:54 -0800 Subject: [PATCH 4/6] Use bin scripts correctly in package.json. --- package.json | 6 +++--- src/grammars/js/formalSyntax.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 735ea04..15e6752 100644 --- a/package.json +++ b/package.json @@ -9,12 +9,12 @@ "main": "src/index.js", "scripts": { "prepublish": "npm start", - "test": "./node_modules/.bin/mocha --reporter spec --recursive", + "test": "mocha --reporter spec --recursive", "start": "./updateCSSData.sh", "clean": "rm -rf src/formatted-data src/grammars/generated", "benchmark": "node test/benchmark.js", - "doctoc": "node ./node_modules/doctoc/doctoc.js README.md", - "lint": "node node_modules/eslint/bin/eslint.js src/", + "doctoc": "doctoc README.md", + "lint": "eslint src/", "precommit-msg": "echo 'Pre-commit checks...' && exit 0" }, "pre-commit": [ diff --git a/src/grammars/js/formalSyntax.js b/src/grammars/js/formalSyntax.js index 13f9539..c28c2c1 100644 --- a/src/grammars/js/formalSyntax.js +++ b/src/grammars/js/formalSyntax.js @@ -1,7 +1,7 @@ -// Generated automatically by nearley +// Generated automatically by nearley, version 2.11.1 // http://github.com/Hardmath123/nearley (function () { -function id(x) {return x[0]; } +function id(x) { return x[0]; } var grammar = { Lexer: undefined, ParserRules: [ From 987e7d832fb44fc4a96a2ecc13c0bc11579b3e88 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Wed, 28 Feb 2018 05:07:48 -0800 Subject: [PATCH 5/6] Bump version to 1.0.6. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 15e6752..030afaa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "css-property-parser", - "version": "1.0.5", + "version": "1.0.6", "description": "Validate css properties and expand shorthand css properties", "keywords": [ "css" From 162156f3a3214d2c13c6aae8e8c5d1d7685c497f Mon Sep 17 00:00:00 2001 From: Alex Orekhov Date: Thu, 28 Jun 2018 12:51:22 +0300 Subject: [PATCH 6/6] Fix redundant quote in ParseError argument --- src/expandShorthandProperty.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/expandShorthandProperty.js b/src/expandShorthandProperty.js index 3946a89..0f84a3d 100644 --- a/src/expandShorthandProperty.js +++ b/src/expandShorthandProperty.js @@ -98,7 +98,7 @@ module.exports = function expandShorthandProperty(propertyName, try { parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar)).feed(formattedPropertyValue); } catch (parseError) { - throw new ParseError(`'Error parsing shorthand property ${propertyName}: ${propertyValue}. ${parseError.message}`); + throw new ParseError(`Error parsing shorthand property ${propertyName}: ${propertyValue}. ${parseError.message}`); } // get the first parsing and use the formatter for the specific shorthand type for this property