commit
4178b18196
|
@ -71,7 +71,10 @@ jobs:
|
|||
- script: |
|
||||
set -e
|
||||
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"
|
||||
yarn lint
|
||||
yarn -s run code-lint --format junit > junit.xml
|
||||
yarn schema-lint
|
||||
yarn type-lint
|
||||
yarn special-lint
|
||||
displayName: "Run linting"
|
||||
- task: PublishTestResults@2
|
||||
inputs:
|
||||
|
|
|
@ -35,6 +35,7 @@ class BasicEvaluatedExpression {
|
|||
this.options = null;
|
||||
this.prefix = null;
|
||||
this.postfix = null;
|
||||
this.wrappedInnerExpressions = null;
|
||||
this.expression = null;
|
||||
}
|
||||
|
||||
|
@ -176,10 +177,11 @@ class BasicEvaluatedExpression {
|
|||
return this;
|
||||
}
|
||||
|
||||
setWrapped(prefix, postfix) {
|
||||
setWrapped(prefix, postfix, innerExpressions) {
|
||||
this.type = TypeWrapped;
|
||||
this.prefix = prefix;
|
||||
this.postfix = postfix;
|
||||
this.wrappedInnerExpressions = innerExpressions;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -174,62 +174,118 @@ class JavascriptParser {
|
|||
right.prefix &&
|
||||
right.prefix.isString()
|
||||
) {
|
||||
// "left" + ("prefix" + inner + "postfix")
|
||||
// => ("leftprefix" + inner + "postfix")
|
||||
res.setWrapped(
|
||||
new BasicEvaluatedExpression()
|
||||
.setString(left.string + right.prefix.string)
|
||||
.setRange(joinRanges(left.range, right.prefix.range)),
|
||||
right.postfix
|
||||
right.postfix,
|
||||
right.wrappedInnerExpressions
|
||||
);
|
||||
} else if (right.isWrapped()) {
|
||||
// "left" + ([null] + inner + "postfix")
|
||||
// => ("left" + inner + "postfix")
|
||||
res.setWrapped(
|
||||
new BasicEvaluatedExpression()
|
||||
.setString(left.string)
|
||||
.setRange(left.range),
|
||||
right.postfix
|
||||
left,
|
||||
right.postfix,
|
||||
right.wrappedInnerExpressions
|
||||
);
|
||||
} else {
|
||||
res.setWrapped(left, null);
|
||||
// "left" + expr
|
||||
// => ("left" + expr + "")
|
||||
res.setWrapped(left, null, [right]);
|
||||
}
|
||||
} else if (left.isNumber()) {
|
||||
if (right.isString()) {
|
||||
res.setString(left.number + right.string);
|
||||
} else if (right.isNumber()) {
|
||||
res.setNumber(left.number + right.number);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (left.isWrapped()) {
|
||||
if (left.postfix && left.postfix.isString() && right.isString()) {
|
||||
// ("prefix" + inner + "postfix") + "right"
|
||||
// => ("prefix" + inner + "postfixright")
|
||||
res.setWrapped(
|
||||
left.prefix,
|
||||
new BasicEvaluatedExpression()
|
||||
.setString(left.postfix.string + right.string)
|
||||
.setRange(joinRanges(left.postfix.range, right.range))
|
||||
.setRange(joinRanges(left.postfix.range, right.range)),
|
||||
left.wrappedInnerExpressions
|
||||
);
|
||||
} else if (
|
||||
left.postfix &&
|
||||
left.postfix.isString() &&
|
||||
right.isNumber()
|
||||
) {
|
||||
// ("prefix" + inner + "postfix") + 123
|
||||
// => ("prefix" + inner + "postfix123")
|
||||
res.setWrapped(
|
||||
left.prefix,
|
||||
new BasicEvaluatedExpression()
|
||||
.setString(left.postfix.string + right.number)
|
||||
.setRange(joinRanges(left.postfix.range, right.range))
|
||||
.setRange(joinRanges(left.postfix.range, right.range)),
|
||||
left.wrappedInnerExpressions
|
||||
);
|
||||
} else if (right.isString()) {
|
||||
res.setWrapped(left.prefix, right);
|
||||
// ("prefix" + inner + [null]) + "right"
|
||||
// => ("prefix" + inner + "right")
|
||||
res.setWrapped(left.prefix, right, left.wrappedInnerExpressions);
|
||||
} else if (right.isNumber()) {
|
||||
// ("prefix" + inner + [null]) + 123
|
||||
// => ("prefix" + inner + "123")
|
||||
res.setWrapped(
|
||||
left.prefix,
|
||||
new BasicEvaluatedExpression()
|
||||
.setString(right.number + "")
|
||||
.setRange(right.range)
|
||||
.setRange(right.range),
|
||||
left.wrappedInnerExpressions
|
||||
);
|
||||
} else if (right.isWrapped()) {
|
||||
// ("prefix1" + inner1 + "postfix1") + ("prefix2" + inner2 + "postfix2")
|
||||
// ("prefix1" + inner1 + "postfix1" + "prefix2" + inner2 + "postfix2")
|
||||
res.setWrapped(
|
||||
left.prefix,
|
||||
right.postfix,
|
||||
left.wrappedInnerExpressions &&
|
||||
right.wrappedInnerExpressions &&
|
||||
left.wrappedInnerExpressions
|
||||
.concat(left.postfix ? [left.postfix] : [])
|
||||
.concat(right.prefix ? [right.prefix] : [])
|
||||
.concat(right.wrappedInnerExpressions)
|
||||
);
|
||||
} else {
|
||||
res.setWrapped(left.prefix, new BasicEvaluatedExpression());
|
||||
// ("prefix" + inner + postfix) + expr
|
||||
// => ("prefix" + inner + postfix + expr + [null])
|
||||
res.setWrapped(
|
||||
left.prefix,
|
||||
null,
|
||||
left.wrappedInnerExpressions &&
|
||||
left.wrappedInnerExpressions.concat(
|
||||
left.postfix ? [left.postfix, right] : [right]
|
||||
)
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (right.isString()) {
|
||||
res.setWrapped(null, right);
|
||||
// left + "right"
|
||||
// => ([null] + left + "right")
|
||||
res.setWrapped(null, right, [left]);
|
||||
} else if (right.isWrapped()) {
|
||||
// left + (prefix + inner + "postfix")
|
||||
// => ([null] + left + prefix + inner + "postfix")
|
||||
res.setWrapped(
|
||||
null,
|
||||
right.postfix,
|
||||
right.wrappedInnerExpressions &&
|
||||
(right.prefix ? [left, right.prefix] : [left]).concat(
|
||||
right.wrappedInnerExpressions
|
||||
)
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
res.setRange(expr.range);
|
||||
|
|
|
@ -178,13 +178,13 @@ ContextDependencyHelpers.create = (
|
|||
);
|
||||
dep.loc = expr.loc;
|
||||
const replaces = [];
|
||||
if (prefixRange && prefix !== prefixRaw) {
|
||||
if (prefixRange) {
|
||||
replaces.push({
|
||||
range: prefixRange,
|
||||
value: JSON.stringify(prefix)
|
||||
});
|
||||
}
|
||||
if (postfixRange && postfix !== postfixRaw) {
|
||||
if (postfixRange) {
|
||||
replaces.push({
|
||||
range: postfixRange,
|
||||
value: JSON.stringify(postfix)
|
||||
|
@ -194,6 +194,13 @@ ContextDependencyHelpers.create = (
|
|||
dep.critical =
|
||||
options.wrappedContextCritical &&
|
||||
"a part of the request of a dependency is an expression";
|
||||
|
||||
if (parser && param.wrappedInnerExpressions) {
|
||||
for (const part of param.wrappedInnerExpressions) {
|
||||
if (part.expression) parser.walkExpression(part.expression);
|
||||
}
|
||||
}
|
||||
|
||||
return dep;
|
||||
} else {
|
||||
const dep = new Dep(
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
"pretest": "yarn lint",
|
||||
"prelint": "yarn setup",
|
||||
"lint": "yarn code-lint && yarn schema-lint && yarn type-lint && yarn special-lint",
|
||||
"code-lint": "eslint --format junit --cache \"{setup,lib,bin,hot,buildin,benchmark,tooling,schemas}/**/*.js\" \"test/*.js\" \"test/{configCases,watchCases,statsCases,hotCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\" > junit.xml",
|
||||
"code-lint": "eslint --cache \"{setup,lib,bin,hot,buildin,benchmark,tooling,schemas}/**/*.js\" \"test/*.js\" \"test/{configCases,watchCases,statsCases,hotCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"",
|
||||
"type-lint": "tsc --pretty",
|
||||
"special-lint": "node tooling/inherit-types && node tooling/format-schemas && node tooling/format-file-header && node tooling/compile-to-definitions",
|
||||
"special-lint-fix": "node tooling/inherit-types --write --override && node tooling/format-schemas --write && node tooling/format-file-header --write && node tooling/compile-to-definitions --write",
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
it("should define FALSE", function() {
|
||||
expect(FALSE).toBe(false);
|
||||
expect((typeof TRUE)).toBe("boolean");
|
||||
var x = require(FALSE ? "fail" : "./a");
|
||||
var y = FALSE ? require("fail") : require("./a");
|
||||
var x = require(FALSE ? "fail" : "./dir/a");
|
||||
var y = FALSE ? require("fail") : require("./dir/a");
|
||||
});
|
||||
|
||||
it("should define CODE", function() {
|
||||
|
@ -118,3 +118,17 @@ it("should follow renamings in var (issue 5215)", function() {
|
|||
it("should check that runtimeValue callback argument is a module", function() {
|
||||
expect(RUNTIMEVALUE_CALLBACK_ARGUMENT_IS_A_MODULE).toEqual(true);
|
||||
});
|
||||
|
||||
it("should expand properly", function() {
|
||||
const a = require("./dir/a");
|
||||
var tmp = '';
|
||||
expect(require('./dir/' + A_DOT_J + tmp + 's')).toBe(a);
|
||||
expect(require('./dir/' + tmp + A_DOT_J + 's')).toBe(a);
|
||||
expect(require('./dir/' + tmp + A_DOT_J + tmp + 's')).toBe(a);
|
||||
expect(require('./dir/' + tmp + A_DOT_J + (tmp + 's'))).toBe(a);
|
||||
expect(require('./dir/' + tmp + (A_DOT_J + tmp + 's'))).toBe(a);
|
||||
expect(require('./dir/' + tmp + (A_DOT_J + tmp) + 's')).toBe(a);
|
||||
expect(require('./dir/' + (tmp + A_DOT_J + tmp + 's'))).toBe(a);
|
||||
expect(require('./dir/' + (tmp + A_DOT_J + tmp) + 's')).toBe(a);
|
||||
expect(require('./dir/' + (tmp + A_DOT_J) + tmp + 's')).toBe(a);
|
||||
});
|
||||
|
|
|
@ -32,7 +32,8 @@ module.exports = {
|
|||
function({ module }) {
|
||||
return module instanceof Module;
|
||||
}
|
||||
)
|
||||
),
|
||||
A_DOT_J: '"a.j"'
|
||||
})
|
||||
]
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue