fix xsslint to work with es6 imports

Change-Id: I97fa2ca9cada24d81a9ced7c8fa7d72997092673
Reviewed-on: https://gerrit.instructure.com/100836
Tested-by: Jenkins
Reviewed-by: Jon Jensen <jon@instructure.com>
Product-Review: Ryan Shaw <ryan@instructure.com>
QA-Review: Ryan Shaw <ryan@instructure.com>
This commit is contained in:
Ryan Shaw 2017-01-29 22:05:05 -07:00
parent 556f0b64bf
commit ea55fff788
2 changed files with 33 additions and 1 deletions

View File

@ -67,8 +67,9 @@ define([
$.ajaxJSON(window.location.href + '/questions?page=' + this.page, 'GET', {}, $.proxy(this.onData, this))
},
onData: function(data){
const html = moveQuestionTemplate(data)
this.elements.$loadMessage.remove()
this.elements.$questions.append(moveQuestionTemplate(data))
this.elements.$questions.append(html)
if (this.page < data.pages){
this.elements.$questions.append(this.elements.$loadMessage)
this.page += 1

View File

@ -32,6 +32,37 @@ Linter.prototype.isSafeString = function(node) {
return (wrapperOption.length > 0)
}
// handle the way babel transforms es6 imports, eg:
// import htmlEscape from 'htmlEscape'
// "foo ${htmlEscape(bar)}"
// which gets converted by babel into:
// var _htmlEscape2 = _interopRequireDefault(_htmlEscape);
// 'foo ' + (0, _htmlEscape2.default)(bar)
const originalIsSafeString = Linter.prototype.isSafeString
Linter.prototype.isSafeString = function isSafeStringWithES6ImportHandling (node) {
const result = originalIsSafeString.call(this, node)
if (result) return result
const callee = node.callee
if (
// look for something like (0, _htmlEscape2.default)(...)
callee && callee.type === 'SequenceExpression' &&
callee.expressions.length === 2 &&
callee.expressions[0].type === 'Literal' &&
callee.expressions[0].value === 0 &&
callee.expressions[1].type === 'MemberExpression' &&
callee.expressions[1].property.name === 'default'
) {
const thingWeActuallyWantToCheck = callee.expressions[1].object
const babelizedFnName = thingWeActuallyWantToCheck.name // eg: "_htmlEscape2"
const originalFnName = babelizedFnName.replace(/^_/, '').replace(/\d$/, '') // eg: 'htmlEscape'
const copyOfNode = Object.assign({}, thingWeActuallyWantToCheck, {name: originalFnName})
if (this.identifierMatches(copyOfNode, 'safeString', '.function')) return true
}
return false
}
function getFilesAndDirs(root, files, dirs) {
root = root === "." ? "" : root + "/";
files = files || [];