Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
- Update Readme.
- Update package.json.
- Update comments in some files.
- Replace node v10 with last in travis config.
- Remove unused eslint configuration.
  • Loading branch information
aMarCruz committed Dec 28, 2018
1 parent fded80d commit c951b3e
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js

node_js:
- "10"
- "node"
- "6.0.0"

branches:
Expand Down
13 changes: 1 addition & 12 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
63 changes: 28 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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 `'<!--'`.
jscc works with _directives_ inserted in the text and prefixed with configurable character sequences, that defaults to `'/*'`, `'//'` and `'<!--'`.

This directives allows you set or get compile-time variables, and exclude code blocks based in its value.

Expand All @@ -83,51 +81,53 @@ To be valid, a `<varname>` must match the regular expression `/^_[0-9A-Z][_0-9A-

> That is, it must start with an underscore, followed by a digit or uppercase letter, and then zero or more underscores, digits or uppercase letters. The character `$` has a special use in jscc and is not allowed for varnames.
### **`#set <varname> [=] <value>`**
### `#set <varname> = <value>`

Defines or redefines a `varname`.

The `value` can be a literal value, another varname, or an expression. If you don't specify a value, it is set to `undefined`.

You can omit the equal sign.

### **`#unset <varname>`**
### `#unset <varname>`

Removes the given `varname`.
Removes the definition of the given `varname`.

Both the definition or removal of a varname take immediate effect.

### **`#if <expression>`**
### `#if <expression>`

Remove the block of code that follows this `#if` if `expression` is _falsy_.

You can nest multiple `#if` blocks.

### **`#ifsef <varname>`**
### `#ifsef <varname>`

Check the existence of a `varname`.

The returned value is `true` if the variable exists, even if its value is `undefined`. Out of this the behavior of `#ifset` is the same as `#if` so references to the latter will imply both.
The returned value is `true` if the variable exists, even if its value is `undefined`. Apart from this, the behavior of `#ifset` is the same as `#if`, so references to the latter will imply both.

### **`#ifnsef <varname>`**
### `#ifnsef <varname>`

This is the opposite to `#ifset`, it returns `false` if the `varname` does not exists.

### **`#elif <expression>`**
### `#elif <expression>`

The behavior of `#elif` is similar to the JS `else if` construction.
The behavior of `#elif` is similar to the JS `else if` statement.

The `expression` will be evaluated if the previous `#if` or `#elif` was _falsy_.

You can have zero or more `#elif` directives following one `#if`.

### **`#endif`**
## `#else`

Includes the block that follows if the previous `#if` or `#elif` expressions were _falsy_.

### `#endif`

Closes the current conditional block.

### **`#error <expression>`**
### `#error <expression>`

Generates an exception at compile time with the result of the character `expression` provided.
Generates an exception at compile time with the result of the given character `expression`.

You can learn more about this in the Wiki:

Expand Down Expand Up @@ -193,35 +193,28 @@ The [MIT](LICENSE) License.

---

[![Codacy][codacy-badge]][codacy-url]
[![Codacy Coverage][codacyc-badge]][codacyc-url]
[![Windows Build][appveypr-badge]][appveypr-url]
[![CodeClimate][climate-badge]][climate-url]
[![CodeClimate Coverage][climatec-badge]][climatec-url]
[![Issues][issues-badge]][issues-url]
[![Vulnerabilities][snyk-badge]][snyk-url]
[![Last commit][commits-badge]][commits-url]

<!-- Badges -->
[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&amp;utm_medium=referral&amp;utm_content=aMarCruz/jscc&amp;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&amp;utm_medium=referral&amp;utm_content=aMarCruz/jscc&amp;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
47 changes: 24 additions & 23 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
Expand All @@ -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
*/
Expand All @@ -86,13 +84,14 @@ declare namespace Jscc {
prefixes?: string | RegExp | Array<string | RegExp>

/**
* 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.
*
Expand All @@ -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
}

}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -28,7 +28,6 @@
},
"keywords": [
"html",
"html5",
"parser",
"javascript",
"typescript",
Expand Down
11 changes: 8 additions & 3 deletions src/get-expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

/**
Expand Down Expand Up @@ -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}`
}
Expand Down
2 changes: 1 addition & 1 deletion src/parse-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
8 changes: 0 additions & 8 deletions test/.eslintrc.yml

This file was deleted.

0 comments on commit c951b3e

Please sign in to comment.