微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.jb51.cc/js/152047.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐