You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

js-conditional-compile-loader

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-conditional-compile-loader - npm Package Compare versions

Comparing version
1.0.10
to
1.0.11
+17
replacer.js
var REG = /\/\*\s*IF(DEBUG|TRUE_\w+)(?:\s*\*\/)?([\s\S]+?)(?:\/\*\s*)?FI\1\s*\*\//g;
exports.replaceMatched = function (js, options) {
return js.replace(REG, (match, $1, $2) => {
var isDropCode;
if ($1 === 'DEBUG') {
isDropCode = options.isDebug === false
} else {
var varName = $1.slice(5)
isDropCode = options[varName] === false
}
return isDropCode ? '' : $2
});
}
// for uint test
exports._reg = REG
+10
-21
var loaderUtils = require('loader-utils');
var REG = /\/\*\s*IF(DEBUG|TRUE\w+)([\s\S]+?)FI\1\s*\*\//g;
var replacer = require('./replacer.js')
var options
module.exports = function (source) {
var options = Object.assign(
{ isDebug: process.env.NODE_ENV === 'development' }, //默认的isDebug
loaderUtils.getOptions(this)
);
return replaceMatched(source, options)
if (!options) {
options = Object.assign(
{ isDebug: process.env.NODE_ENV === 'development' }, //默认的isDebug
loaderUtils.getOptions(this)
);
}
return replacer.replaceMatched(source, options)
};
module.exports._rp = replaceMatched
module.exports._reg = REG
function replaceMatched(js, options) {
return js.replace(REG, (match, $1, $2) => {
var isDropCode;
if ($1 === 'DEBUG') {
isDropCode = options.isDebug === false
} else {
var varName = $1.slice(5)
isDropCode = options[varName] === false
}
return isDropCode ? '' : $2
});
}

@@ -0,0 +0,0 @@ MIT License

{
"name": "js-conditional-compile-loader",
"version": "1.0.10",
"version": "1.0.11",
"description": "A javascript conditional compile loader for webpack. 一个javascript条件编译的webpack loader。",

@@ -10,4 +10,3 @@ "main": "index.js",

},
"dependencies": {
},
"dependencies": {},
"keywords": [

@@ -30,3 +29,6 @@ "webpack",

"loader-utils": "^1.2.3"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
}
}
# js-conditional-compile-loader
一个javascript条件编译的webpack loader。
条件编译指按照需要,按照环境设置的条件,选择性地编译或不编译指定的代码。
- [English](https://github.com/hzsrc/js-conditional-compile-loader/blob/master/readme.md)
一个javascript条件编译的webpack loader。
条件编译指按照需要,按照环境设置的条件,选择性地编译或不编译指定的代码。
比如:用一套代码实现debug和release环境输出两套不同js程序。

@@ -9,3 +11,5 @@

这样用就行:
以`/*IFDEBUG`、`/*IFTRUE_xxx`开头,以`FIDEBUG*/`、`FITRUE_xxx*/`结尾,中间是js代码。可以用在js文件的任意地方。
- 模式1 - 全注释:
因为采用了js注释的形式,故即使不使用js-conditional-compile-loader,也不影响js代码的运行逻辑。
````js

@@ -18,31 +22,43 @@ /*IFDEBUG Any js here FIDEBUG*/

````
以“/\*IFDEBUG”开头,以“FIDEBUG\*/”结尾,中间是js代码。可以用在js文件的任意地方。
- 模式2(首+尾):
这种模式下,可使用eslint校验你的代码。
````js
/* IFDEBUG */
var anyJsHere = 'Any js here'
/*FIDEBUG */
````
or
````js
/* IFTRUE_yourFlagName*/
function anyJsHere(){
}
/*FITRUE_yourFlagName */
````
* sample -- sorce code:
----
### 由源码输出的结果
源码:
````js
/* IFTRUE_forAlibaba */
var aliCode = require('./ali/alibaba-business.js')
aliCode.doSomething()
/* FITRUE_forAlibaba */
$state.go('win', {dir: menu.winId /*IFDEBUG , reload: true FIDEBUG*/})
````
Output for debug:
options为`{isDebug: true, forAlibaba: true}`时,构建后输出的内容:
````js
var aliCode = require('./ali/alibaba-business.js')
aliCode.doSomething()
$state.go('win', {dir: menu.winId, reload: true })
````
Output of production:
options为`{isDebug: false, forAlibaba: false}`时,构建后输出的内容:
````js
$state.go('win', {dir: menu.winId})
````
----
* sample2:
````js
var tx = "This is app /* IFTRUE_Ali of debug FITRUE_Ali */ here";
````
* sample3:
````js
/*IFDEBUG
alert('Hi~');
FIDEBUG*/
````
因为采用了js注释的形式,故即使不使用js-conditional-compile-loader,也不影响js代码的运行逻辑。
### 安装

@@ -63,5 +79,2 @@ ````bash

include: [resolve('src'), resolve('test')],
exclude: file => (
/node_modules/.test(file) && !/\.vue\.js/.test(file)
),
use: [

@@ -94,3 +107,16 @@ //step-2

## 用法举例
* 1
* 1:
````js
var tx = "This is app /* IFTRUE_Ali of debug FITRUE_Ali */ here";
````
* 2:
````js
/*IFDEBUG
alert('Hi~');
FIDEBUG*/
````
* 3
```js

@@ -104,7 +130,7 @@ Vue.component('debugInfo', {

watch: {
/* IFDEBUG
/* IFTRUE_myFlag */
curRule (v){
this.ruleData = v
},
FIDEBUG */
/*FITRUE_myFlag */
},

@@ -114,3 +140,3 @@ });

* 2
* 4
```javascript

@@ -125,6 +151,6 @@ import { Layout } from 'my-layout-component'

export default {
components: {
LayoutRun
},
components: {
LayoutRun
},
}
```
+57
-31
# js-conditional-compile-loader
A javascript conditional compiling loader for webpack.
Conditional compiling means that we can compile or not compile some js code according to some environment variables.
- [中文文档](https://github.com/hzsrc/js-conditional-compile-loader/blob/master/readme-cn.md)
A javascript conditional compiling loader for webpack.
Conditional compiling means that we can compile or not compile some js code according to some environment variables.
For example: we can output two different program for debug or release environment with a same source code project.

@@ -9,3 +11,6 @@

Just use it anywhere in js code like this:
Start with `/*IFDEBUG` or `/*IFTRUE_xxx`, end with `FIDEBUG*/` or `FITRUE_xxx*/`, place js code in the center. you can use it any where in js files.
- Mode 1 - comment all
Since it is designed by a js comment style, the code can run normaly even though the js-conditional-compile-loader is not used.
````js

@@ -18,30 +23,40 @@ /* IFDEBUG Any js here FIDEBUG */

````
Start with "/\*IFDEBUG", end with"FIDEBUG\*/", and js code in the center. you can use it any where in js files.
* sample -- sorce code:
- Mode 2 -- head and foot
In this mode, you can use eslint to check your code.
````js
$state.go('win', {dir: menu.winId /*IFDEBUG , reload: true FIDEBUG*/})
/* IFDEBUG */
var anyJsHere = 'Any js here'
/*FIDEBUG */
````
Output for debug:
or
````js
$state.go('win', {dir: menu.winId, reload: true })
/* IFTRUE_yourFlagName*/
function anyJsHere(){
}
/*FITRUE_yourFlagName */
````
Output of production:
----
### Build result with source code
Source code:
````js
$state.go('win', {dir: menu.winId})
/* IFTRUE_forAlibaba */
var aliCode = require('./ali/alibaba-business.js')
aliCode.doSomething()
/* FITRUE_forAlibaba */
$state.go('win', {dir: menu.winId /*IFDEBUG , reload: true FIDEBUG*/})
````
* sample2:
Compiled output by options: `{isDebug: true, forAlibaba: true}`:
````js
var tx = "This is app /* IFTRUE_Ali of debug FITRUE_Ali */ here";
var aliCode = require('./ali/alibaba-business.js')
aliCode.doSomething()
$state.go('win', {dir: menu.winId, reload: true })
````
* sample3:
Compiled output by options: `{isDebug: false, forAlibaba: false}`:
````js
/*IFDEBUG
alert('Hi~');
FIDEBUG*/
$state.go('win', {dir: menu.winId})
````
Since it is designed by a js comment style, the code can run normaly even though the js-conditional-compile-loader is not used.
----

@@ -63,5 +78,2 @@ ### Setup

include: [resolve('src'), resolve('test')],
exclude: file => (
/node_modules/.test(file) && !/\.vue\.js/.test(file)
),
use: [

@@ -74,3 +86,3 @@ //step-2

options: {
isDebug: process.env.NODE_ENV === 'development', // optional, this is default
isDebug: process.env.NODE_ENV === 'development', // optional, this expression is default
myFlag: process.env.ENV_COMPANY === 'ALI', // any name you want, used for /* IFTRUE_myFlag ...js code... FITRUE_myFlag */

@@ -96,3 +108,17 @@ }

## Samples
* 1
* 1:
````js
var tx = "This is app /* IFTRUE_Ali of debug FITRUE_Ali */ here";
````
* 2:
````js
/*IFDEBUG
alert('Hi~');
FIDEBUG*/
````
* 3
```js

@@ -106,7 +132,7 @@ Vue.component('debugInfo', {

watch: {
/* IFDEBUG
/* IFTRUE_myFlag */
curRule (v){
this.ruleData = v
},
FIDEBUG */
/*FITRUE_myFlag */
},

@@ -116,3 +142,3 @@ });

* 2
* 4
```javascript

@@ -122,11 +148,11 @@ import { Layout } from 'my-layout-component'

/* IFDEBUG
import FpLayoutLocal from '../../local-code/my-layout-component/src/components/layout.vue'
LayoutRun = FpLayoutLocal
import LayoutLocal from '../../local-code/my-layout-component/src/components/layout.vue'
LayoutRun = LayoutLocal
FIDEBUG */
export default {
components: {
LayoutRun
},
components: {
LayoutRun
},
}
```
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>

Sorry, the diff of this file is not supported yet

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/js-conditional-compile-loader.iml" filepath="$PROJECT_DIR$/.idea/js-conditional-compile-loader.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="d3bd5335-f959-4ad3-b315-9847a84a2d6e" name="Default Changelist" comment="samples">
<change afterPath="$PROJECT_DIR$/readme-cn.md" afterDir="false" />
<change afterPath="$PROJECT_DIR$/test/index.test.js" afterDir="false" />
<change afterPath="$PROJECT_DIR$/test/src/IFDEBUG.js" afterDir="false" />
<change afterPath="$PROJECT_DIR$/test/src/IFTRUE.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/index.js" beforeDir="false" afterPath="$PROJECT_DIR$/index.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
<change beforePath="$PROJECT_DIR$/readme.md" beforeDir="false" afterPath="$PROJECT_DIR$/readme.md" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/.tmp/" />
<ignored path="$PROJECT_DIR$/temp/" />
<ignored path="$PROJECT_DIR$/tmp/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="375">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/index.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="266">
<caret line="14" column="45" lean-forward="true" selection-start-line="14" selection-start-column="45" selection-end-line="14" selection-end-column="45" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/readme.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="281">
<caret line="86" column="124" selection-start-line="86" selection-start-column="124" selection-end-line="86" selection-end-column="124" />
<folding>
<element signature="n#!!doc" expanded="true" />
<element signature="n#!!doc" expanded="true" />
<element signature="n#!!doc" expanded="true" />
</folding>
</first_editor>
<second_editor />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/package.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="95">
<caret line="5" column="14" lean-forward="true" selection-start-line="5" selection-start-column="14" selection-end-line="5" selection-end-column="14" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/index.test.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="232">
<caret line="22" column="81" selection-start-line="22" selection-start-column="81" selection-end-line="22" selection-end-column="81" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/src/IFTRUE.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="133">
<caret line="7" column="20" selection-start-line="7" selection-start-column="20" selection-end-line="7" selection-end-column="20" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test/src/IFDEBUG.js">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret selection-end-line="13" selection-end-column="2" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/readme-cn.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="396">
<caret line="95" column="23" selection-start-line="95" selection-start-column="22" selection-end-line="95" selection-end-column="23" />
<folding>
<element signature="n#!!doc" expanded="true" />
<element signature="n#!!doc" expanded="true" />
</folding>
</first_editor>
<second_editor />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/LICENSE">
<provider selected="true" editor-type-id="text-editor" />
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="JavaScript File" />
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>loader-utils</find>
<find>REG</find>
<find>replaceIfDebug</find>
<find>&quot;</find>
</findStrings>
<replaceStrings>
<replace>replaceMatched</replace>
<replace>`</replace>
</replaceStrings>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/test/src/index.js" />
<option value="$PROJECT_DIR$/test/index.js" />
<option value="$PROJECT_DIR$/test/src/IFTRUE.js" />
<option value="$PROJECT_DIR$/test/index.test.js" />
<option value="$PROJECT_DIR$/index.js" />
<option value="$PROJECT_DIR$/readme.md" />
<option value="$PROJECT_DIR$/readme-cn.md" />
<option value="$PROJECT_DIR$/package.json" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="y" value="23" />
<option name="width" value="1920" />
<option name="height" value="1007" />
</component>
<component name="ProjectLevelVcsManager">
<OptionsSetting value="false" id="Update" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="js-conditional-compile-loader" type="b2602c69:ProjectViewProjectNode" />
<item name="js-conditional-compile-loader" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="js-conditional-compile-loader" type="b2602c69:ProjectViewProjectNode" />
<item name="js-conditional-compile-loader" type="462c0819:PsiDirectoryNode" />
<item name="test" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="js-conditional-compile-loader" type="b2602c69:ProjectViewProjectNode" />
<item name="js-conditional-compile-loader" type="462c0819:PsiDirectoryNode" />
<item name="test" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="D:/nodejs/node" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="web.server" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/test" />
</key>
<key name="CopyFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/test/src" />
<recent name="$PROJECT_DIR$" />
</key>
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration>$USER_HOME$/.subversion</configuration>
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="d3bd5335-f959-4ad3-b315-9847a84a2d6e" name="Default Changelist" comment="" />
<created>1550026768082</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1550026768082</updated>
<workItem from="1550026769527" duration="2082000" />
<workItem from="1550035725709" duration="20000" />
<workItem from="1550035779954" duration="9000" />
<workItem from="1555293564344" duration="292000" />
<workItem from="1555580002774" duration="1492000" />
<workItem from="1563169454198" duration="6088000" />
</task>
<task id="LOCAL-00001" summary="空格支持">
<created>1550026883967</created>
<option name="number" value="00001" />
<option name="presentableId" value="LOCAL-00001" />
<option name="project" value="LOCAL" />
<updated>1550026883967</updated>
</task>
<task id="LOCAL-00002" summary="空格支持">
<created>1550027635865</created>
<option name="number" value="00002" />
<option name="presentableId" value="LOCAL-00002" />
<option name="project" value="LOCAL" />
<updated>1550027635865</updated>
</task>
<task id="LOCAL-00003" summary="samples">
<created>1555581893764</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1555581893764</updated>
</task>
<option name="localTasksCounter" value="4" />
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="9983000" />
</component>
<component name="ToolWindowManager">
<frame x="0" y="23" width="1920" height="1008" extended-state="6" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.24973601" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="npm" order="2" side_tool="true" />
<window_info id="Favorites" order="3" side_tool="true" />
<window_info anchor="bottom" id="Messages" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="bottom" id="Event Log" order="9" side_tool="true" />
<window_info anchor="bottom" id="Terminal" order="10" visible="true" weight="0.24860647" />
<window_info anchor="right" id="Commander" order="0" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="空格支持" />
<MESSAGE value="samples" />
<option name="LAST_COMMIT_MESSAGE" value="samples" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/LICENSE">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/node_modules/loader-utils/lib/index.js">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/test/src/IFDEBUG.js">
<provider selected="true" editor-type-id="text-editor">
<state>
<caret selection-end-line="13" selection-end-column="2" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/src/IFTRUE.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="133">
<caret line="7" column="20" selection-start-line="7" selection-start-column="20" selection-end-line="7" selection-end-column="20" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/index.test.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="232">
<caret line="22" column="81" selection-start-line="22" selection-start-column="81" selection-end-line="22" selection-end-column="81" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/readme.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="281">
<caret line="86" column="124" selection-start-line="86" selection-start-column="124" selection-end-line="86" selection-end-column="124" />
<folding>
<element signature="n#!!doc" expanded="true" />
<element signature="n#!!doc" expanded="true" />
<element signature="n#!!doc" expanded="true" />
</folding>
</first_editor>
<second_editor />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/readme-cn.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="396">
<caret line="95" column="23" selection-start-line="95" selection-start-column="22" selection-end-line="95" selection-end-column="23" />
<folding>
<element signature="n#!!doc" expanded="true" />
<element signature="n#!!doc" expanded="true" />
</folding>
</first_editor>
<second_editor />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/index.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="266">
<caret line="14" column="45" lean-forward="true" selection-start-line="14" selection-start-column="45" selection-end-line="14" selection-end-column="45" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/package.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="95">
<caret line="5" column="14" lean-forward="true" selection-start-line="5" selection-start-column="14" selection-end-line="5" selection-end-column="14" />
</state>
</provider>
</entry>
</component>
</project>
var plugin = require('../index')
var glob = require('glob')
var fs = require('fs')
var path = require('path')
var resolve = path.resolve.bind(null, __dirname)
// glob(resolve('./src/**/*.js'), function (er, files) {
// if (er) throw er
// files.map(file => {
// })
// })
test('IFDEBUG true', () => {
testOne('src/IFDEBUG.js', { isDebug: true }, /font-size:13px[\s\S]+this.ruleData/)
})
test('IFDEBUG false', () => {
testOne('src/IFDEBUG.js', { isDebug: false }, /template: ''\s+,\s+watch: \{\s+\}/)
})
test('IFTRUE myFlag=true', () => {
testOne('src/IFTRUE.js', { myFlag: true }, /font-size:13px[\s\S]+this.ruleData/)
})
test('IFTRUE myFlag=false', () => {
testOne('src/IFTRUE.js', { myFlag: false }, /template: ''\s+,\s+watch: \{\s+\}/)
})
function testOne(file, options, reg, notReg) {
var src = fs.readFileSync(resolve(file), 'utf-8')
var result = plugin._rp(src, options)
expect(result).toMatch(reg)
expect(result).not.toMatch(plugin._reg)
}
var vueComponent = {
template: ''
/* IFDEBUG
+ '<pre style="font-size:13px;font-family:\'Courier\',\'Courier New\';z-index:9999;line-height: 1.1;position: fixed;top:0;right:0; pointer-events: none">{{JSON.stringify($attrs.info || "", null, 4).replace(/"(\\w+)":/g, "$1:")}}</pre>'
FIDEBUG */
,
watch: {
/* IFDEBUG
curRule (v){
this.ruleData = v
},
FIDEBUG */
},
};
var vueComponent = {
template: ''
/* IFTRUE_myFlag
+ '<pre style="font-size:13px;font-family:\'Courier\',\'Courier New\';z-index:9999;line-height: 1.1;position: fixed;top:0;right:0; pointer-events: none">{{JSON.stringify($attrs.info || "", null, 4).replace(/"(\\w+)":/g, "$1:")}}</pre>'
FITRUE_myFlag */
,
watch: {
/* IFTRUE_myFlag
curRule (v){
this.ruleData = v
},
FITRUE_myFlag */
},
};