MVC4捆绑小工具不支持JavaScript保留字

前端之家收集整理的这篇文章主要介绍了MVC4捆绑小工具不支持JavaScript保留字前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
使用最新版本的MVC4,当它包含保留字作为关键名字时,我无法最小化 javascript

请看下面的错误,使用应该已经被细化的有效的javascript.

有没有人知道如何解决这个短的重写javascript来使用[“”]符号?

PS有问题的代码是几千行长,所以不是一个选择!

/* Minification Failed. Returning unminified contents.
(3,9-15): run-time warning JS1010: Expected identifier: delete
(4,9-13): run-time warning JS1010: Expected identifier: case
(5,9-11): run-time warning JS1010: Expected identifier: if
(3,9-15): run-time error JS1137: 'delete' is a new reserved word and should not be used as an identifier: delete
(4,9-13): run-time error JS1137: 'case' is a new reserved word and should not be used as an identifier: case
(5,9-11): run-time error JS1137: 'if' is a new reserved word and should not be used as an identifier: if
 */
var context = {};

context.delete = {};
context.case = {};
context.if = {};

这个问题不是像节点,盒式磁带,梳子,服务器等其他选项

我们如何让MVC4用保留字播球.

我觉得很难相信,6个月以后再也没有这个支持

解决方法

只是试过这个,它的作品.对不起,但丑的代码.它将替换您的名为delete的用户及其用法.
public class CustomBundle : ScriptBundle
{
    public CustomBundle(string virtualPath) : base(virtualPath)
    {
        this.Builder = new CustomBuilder();
    }
    public CustomBundle(string virtualPath,string cdnPath) : base(virtualPath,cdnPath) {}
}

public class CustomBuilder : IBundleBuilder {
    public string BuildBundleContent(Bundle bundle,BundleContext context,IEnumerable<FileInfo> files)
    {
        var content = new StringBuilder();
        foreach (var fileInfo in files)
        {
            var parser = new Microsoft.Ajax.Utilities.JSParser(Read(fileInfo));
            parser.Settings.AddRenamePair("delete","fooDelete");
            content.Append(parser.Parse(parser.Settings).ToCode());
            content.Append(";");
        }

        return content.ToString();
    }

    private string Read(FileInfo file)
    {
        using(var r = file.OpenText())
        {
            return r.ReadToEnd();
        }
    }
}
原文链接:https://www.f2er.com/js/152047.html

猜你在找的JavaScript相关文章