From c951b3e884d0f1b6defdb8d32cb4b7b6e2ba5946 Mon Sep 17 00:00:00 2001 From: aMarCruz Date: Fri, 28 Dec 2018 05:40:47 -0600 Subject: [PATCH] v1.1.1 - Update Readme. - Update package.json. - Update comments in some files. - Replace node v10 with last in travis config. - Remove unused eslint configuration. --- .travis.yml | 2 +- .vscode/settings.json | 13 +-------- CHANGELOG.md | 3 +++ README.md | 63 +++++++++++++++++++------------------------ index.d.ts | 47 ++++++++++++++++---------------- package.json | 3 +-- src/get-expr.ts | 11 +++++--- src/parse-options.ts | 2 +- src/parser.ts | 8 ------ test/.eslintrc.yml | 8 ------ 10 files changed, 67 insertions(+), 93 deletions(-) delete mode 100644 test/.eslintrc.yml diff --git a/.travis.yml b/.travis.yml index a5df94d..8901477 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: - - "10" + - "node" - "6.0.0" branches: diff --git a/.vscode/settings.json b/.vscode/settings.json index bc4c69e..4dbed95 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,16 +6,5 @@ "typescript.format.insertSpaceAfterConstructor": true, "typescript.format.insertSpaceBeforeFunctionParenthesis": true, "typescript.suggest.completeFunctionCalls": true, - "typescript.tsdk": "node_modules/typescript/lib", - "eslint.enable": true, - "eslint.packageManager": "yarn", - "eslint.validate": [ - "javascript", - "javascriptreact", - ], - "eslint.workingDirectories": [ - "./src", - "./test" - ], - "todo-tree.rootFolder": "${workspaceFolder}/src", + "typescript.tsdk": "node_modules/typescript/lib" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 6994d7f..2ee4e14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Revised .gitignore - Update dependencies and devDependencies. +- Update Readme. +- Replace node 10 with the 'node' in travis config. ### Fixed @@ -25,6 +27,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Removed - .npmignore, now using package.json 'files' property. +- unused ESLint configuration. ## \[1.1.0] - 2018-11-22 diff --git a/README.md b/README.md index f7b8474..967cd86 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,10 @@ # jscc [![jscc on npm][npm-badge]][npm-url] -[![Windows Build][appveypr-badge]][appveypr-url] +[![License MIT][license-badge]][license-url] [![Linux Build][travis-badge]][travis-url] -[![Codebeat][codebeat-badge]][codebeat-url] +[![Codacy][codacy-badge]][codacy-url] [![Coverage][codecov-badge]][codecov-url] -[![Vulnerabilities][snyk-badge]][snyk-url] -[![License MIT][license-badge]][license-url] Featuring some of the C preprocessor characteristics through special, configurable comments, jscc can be used in any type of files to build multiple versions of your software from the same code base. @@ -73,7 +71,7 @@ Please see the Wiki to know the supported [options](https://github.com/aMarCruz/ ## Directives -jscc works with _directives_ inserted in the text files and prefixed with configurable character sequences, that defaults to `'/*'`, `'//'` and `' [npm-badge]: https://img.shields.io/npm/v/jscc.svg [npm-url]: https://www.npmjs.com/package/jscc -[license-badge]: https://img.shields.io/github/license/mashape/apistatus.svg +[license-badge]: https://img.shields.io/npm/l/jscc.svg?colorB=blue [license-url]: https://github.com/aMarCruz/jscc/blob/master/LICENSE [appveypr-badge]: https://ci.appveyor.com/api/projects/status/hdsef0p6q0oqr127?svg=true [appveypr-url]: https://ci.appveyor.com/project/aMarCruz/jscc -[travis-badge]: https://img.shields.io/travis/aMarCruz/jscc.svg +[travis-badge]: https://img.shields.io/travis/aMarCruz/jscc.svg?label=travis [travis-url]: https://travis-ci.org/aMarCruz/jscc [snyk-badge]: https://snyk.io/test/github/aMarCruz/jscc/badge.svg?targetFile=package.json [snyk-url]: https://snyk.io/test/github/aMarCruz/jscc?targetFile=package.json -[codacy-badge]: https://api.codacy.com/project/badge/Grade/30e8679fcd614227837ad250dd6c4030 +[codacy-badge]: https://img.shields.io/codacy/grade/30e8679fcd614227837ad250dd6c4030.svg [codacy-url]: https://www.codacy.com/app/aMarCruz/jscc?utm_source=github.com&utm_medium=referral&utm_content=aMarCruz/jscc&utm_campaign=Badge_Grade -[codacyc-badge]: https://api.codacy.com/project/badge/Coverage/30e8679fcd614227837ad250dd6c4030 -[codacyc-url]: https://www.codacy.com/app/aMarCruz/jscc?utm_source=github.com&utm_medium=referral&utm_content=aMarCruz/jscc&utm_campaign=Badge_Coverage -[codebeat-badge]: https://codebeat.co/badges/7e15dc9d-42a8-4ea2-8bae-a21c09490fbe -[codebeat-url]: https://codebeat.co/projects/github-com-amarcruz-jscc-dev -[codecov-badge]: https://codecov.io/gh/aMarCruz/jscc/branch/dev/graph/badge.svg +[codecov-badge]: https://img.shields.io/codecov/c/github/aMarCruz/jscc.svg [codecov-url]: https://codecov.io/gh/aMarCruz/jscc [climate-badge]: https://codeclimate.com/github/aMarCruz/jscc/badges/gpa.svg [climate-url]: https://codeclimate.com/github/aMarCruz/jscc -[issues-badge]: https://codeclimate.com/github/aMarCruz/jscc/badges/issue_count.svg -[issues-url]: https://codeclimate.com/github/aMarCruz/jscc -[climatec-badge]: https://api.codeclimate.com/v1/badges/50d60a10ec7c9156b429/test_coverage -[climatec-url]: https://codeclimate.com/github/aMarCruz/jscc/test_coverage +[commits-badge]: https://img.shields.io/github/last-commit/aMarCruz/jscc.svg +[commits-url]: https://github.com/aMarCruz/jscc/commits/master [kofi-url]: https://ko-fi.com/C0C7LF7I diff --git a/index.d.ts b/index.d.ts index d46948f..c594e28 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,14 +1,12 @@ /* - jscc v1.0 - - @author aMarCruz + Type definitions for jscc v1.1.1 @license MIT */ export = Jscc /** - * Preprocessor for conditional comments and compile-time variable - * replacement replacement in text files (asynchronous version). + * Preprocessor for conditional comments and replacement of compile-time + * variables in text files (asynchronous version). * * @param source String to be preprocessed, encoded in utf8. * @param filename Absolute or relative path to the current directory. @@ -23,8 +21,8 @@ declare function Jscc ( ): void /** - * Preprocessor for conditional comments and compile-time variable - * replacement replacement in text files (synchronous version). + * Preprocessor for conditional comments and replacement of compile-time + * variables in text files (synchronous version). * * @param source String to be preprocessed, encoded in utf8. * @param filename Absolute or relative path to the current directory. @@ -47,31 +45,31 @@ declare namespace Jscc { * String with the type of quotes to escape in the output of strings: * 'single', 'double' or 'both'. * - * It does not affects the output of regexes or strings contained in the - * JSON output of objects. + * It does not affects the strings contained in the JSON output of + * objects. */ escapeQuotes?: QuoteType /** - * Allows to preserve the empty lines of the directives and blocks that + * Allows to preserve the empty lines of directives and blocks that * were removed. * - * Use this option with `sourceMap:false` if you are only interested in - * keeping the line count. + * Use this option with `sourceMap:false` if you are interested only in + * preserve the line count. * * @default false */ keepLines?: boolean /** - * Include the original source in the sourceMap. + * Include the original source in the sourcemap. * * @default false */ mapContent?: boolean /** - * Makes a hi-res sourceMap. + * Makes a hi-res sourcemap. * * @default true */ @@ -86,13 +84,14 @@ declare namespace Jscc { prefixes?: string | RegExp | Array /** - * Set this option to `false` to suppress source map generation. + * Set this option to `false` to suppress the creation of the sourcemap. * - * _Note:_ In plugins like rollup-plugin-jscc or jscc-brunch, this option - * should take its value from equivalent property of the parent tool. + * _Note:_ In plugins such as jscc-brunch, this option will take the value + * given by the main tool, unless it is explicity defined as `false` * @default true */ sourceMap?: boolean + /** * Plain object defining the variables used by jscc during the preprocessing. * @@ -107,24 +106,26 @@ declare namespace Jscc { } /** - * The result always will be an object with a `code` property and, if - * `sourceMap` is required (the default), a `map` property with a raw - * sourceMap, or `null` if the buffer did not change. - * - * If `sourceMap` is not required, the `map` property is ommited. + * The result */ interface Result { + /** + * Processed source text. + */ code: string + /** + * Raw sourcemap object, or `null` if the buffer did not change. + */ map?: import('magic-string').SourceMap | null } /** Callback for async operation */ type Callback = (error: Error | null, data?: Jscc.Result) => void + /** jscc varnames and values */ interface Values { [k: string]: any _VERSION: string _FILE: string } - } diff --git a/package.json b/package.json index a8df6b3..85959c6 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jscc", "version": "1.1.1", - "description": "Tiny and powerful preprocessor for conditional comments and compile-time replacements in source files", + "description": "Tiny and powerful preprocessor for conditional comments and replacement of compile-time variables in text files", "main": "dist/jscc.js", "source": "src/jscc.ts", "types": "index.d.ts", @@ -28,7 +28,6 @@ }, "keywords": [ "html", - "html5", "parser", "javascript", "typescript", diff --git a/src/get-expr.ts b/src/get-expr.ts index b0218d9..357800f 100644 --- a/src/get-expr.ts +++ b/src/get-expr.ts @@ -67,6 +67,10 @@ const skipBracket = (expr: string, start: number, stack: string[]) => { return ch ? start + 1 : expr.length } +/** + * To find the comment (//), it is necessary to skip strings, es6 tl, + * brackets, and regexes + */ const RE_EXPR = RegExp(R.S_STRINGS + '|[`/{}]', 'g') /** @@ -119,14 +123,15 @@ const getExpr = function (key: string, expr: string) { } /* - When an assignment has a regex (ex: _R /\s/), skipRegex will not - recognize this due the invalid syntax. By inserting '=' fix it. + When an assignment has a regex (ex: `#set _R /\s/`), skipRegex will not + recognize it due to invalid syntax. Inserting the missing '=' solves this. */ if (key === 'set') { const mm = R.ASSIGNMENT.exec(expr)! const ss = mm && mm[2] - // care of something like `//#set _V //cmnt` + // beware of something like `//#set _V //cmnt` + // istanbul ignore else if (ss) { expr = ss.startsWith('//') ? mm[1] : `${mm[1]}=${ss}` } diff --git a/src/parse-options.ts b/src/parse-options.ts index 16beacc..b231f1a 100644 --- a/src/parse-options.ts +++ b/src/parse-options.ts @@ -159,13 +159,13 @@ const parseOptions = function _parseOptions (filename: string, opts: Jscc.Option // Create and returns the normalized jscc props, we are done return { magicStr: {} as any, // makes TS happy + errorHandler, escapeQuotes, keepLines: !!opts.keepLines, mapContent: !!opts.mapContent, mapHires: opts.mapHires !== false, sourceMap: opts.sourceMap !== false, prefixes, - errorHandler, values, } } diff --git a/src/parser.ts b/src/parser.ts index b4ccb4c..9de6131 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -38,14 +38,6 @@ const ENDIF_MASK = Block.IF | Block.ELSE */ const S_RE_BASE = /^[ \t\f\v]*(?:@)#(if|ifn?set|elif|else|endif|set|unset|error)(?:(?=[ \t])(.*)|\/\/.*)?$/.source -/** - * Matches a quoted string or a substring that includes the first unquoted - * double slash (the starting of one-line comments) in a line. - * - * $1: If the regex found a comment, it is '//', otherwise, it is `undefined` - */ -// const R_LINECMNT = RegExp(`${R.S_STRINGS}|(/)`, 'g') - /** * Conditional comments parser * diff --git a/test/.eslintrc.yml b/test/.eslintrc.yml deleted file mode 100644 index f08742d..0000000 --- a/test/.eslintrc.yml +++ /dev/null @@ -1,8 +0,0 @@ -env: - mocha: true - es6: false - -rules: - no-console: 0 - no-debugger: 0 - prefer-template: 0