Exemplo n.º 1
0
        public void CompileFailsGracefullyOnMono()
        {
            var compiler  = new CoffeeScriptCompiler();
            var exception = Assert.Throws(typeof(NotSupportedException), () => compiler.Compile(""));

            Assert.AreEqual("Coffeescript not yet supported for mono.", exception.Message);
        }
Exemplo n.º 2
0
        public void CompileWithComplexScriptSucceeds()
        {
            string source = @"# Assignment:
number   = 42
opposite = true

# Conditions:
number = -42 if opposite

# Functions:
square = (x) -> x * x

# Arrays:
list = [1, 2, 3, 4, 5]

# Objects:
math =
  root:   Math.sqrt
  square: square
  cube:   (x) -> x * square x

# Splats:
race = (winner, runners...) ->
  print winner, runners

# Existence:
alert 'I knew it!' if elvis?";

            var compiler = new CoffeeScriptCompiler();

            compiler.Compile(source);
        }
 public string Compile(string code)
 {
     lock (Lock)
     {
         return(_coffeeScriptCompiler.Compile(code));
     }
 }
Exemplo n.º 4
0
 public void CompileFile_with_valid_CoffeeScript_returns_JavaScript()
 {
     var source = "x = 1";
     var compiler = new CoffeeScriptCompiler();
     var javaScript = compiler.Compile(source, Mock.Of<IFile>());
     javaScript.ShouldEqual("(function() {\n  var x;\n  x = 1;\n}).call(this);\n");
 }
        public void CoffeeScriptFailTest()
        {
            var input = "test.invlid.stuff/^/g!%%";

            using (var fixture = new CoffeeScriptCompiler(new InstanceProvider <IJavaScriptRuntime>(
                                                              () => new IEJavaScriptRuntime()))) {
                bool shouldDie = false;

                try {
                    var result = fixture.Compile(input);
                    if (result.StartsWith("ENGINE FAULT"))
                    {
                        shouldDie = true;
                    }
                    else
                    {
                        Console.WriteLine(result);
                    }
                } catch (Exception ex) {
                    Console.WriteLine("Ex: " + ex.Message);
                    shouldDie = true;
                }

                Assert.True(shouldDie);
            }
        }
Exemplo n.º 6
0
 public override IProcessResult Process(string filePath, string content)
 {
     using (var compiler = new CoffeeScriptCompiler())
     {
         return(new ProcessResult(compiler.Compile(content)));
     }
 }
Exemplo n.º 7
0
        public void CompileWithSimpleAlertSucceeds()
        {
            var compiler = new CoffeeScriptCompiler();

            string result = compiler.Compile("alert 'test' ");

            Assert.AreEqual("(function() {\n  alert('test');\n}).call(this);\n", result);
        }
        public void CoffeeScriptSmokeTest()
        {
            var input = @"v = x*5 for x in [1...10]";
            var fixture = new CoffeeScriptCompiler();

            var result = fixture.Compile(input);
            Assert.False(String.IsNullOrWhiteSpace(result));
        }
        public void CoffeeScriptSmokeTest()
        {
            var input = @"v = x*5 for x in [1...10]";

            using (var fixture = new CoffeeScriptCompiler(new InstanceProvider <IJavaScriptRuntime>(
                                                              () => new IEJavaScriptRuntime()))) {
                var result = fixture.Compile(input);
                Assert.False(String.IsNullOrWhiteSpace(result));
            }
        }
Exemplo n.º 10
0
 public void CompileFile_with_invalid_CoffeeScript_throws_CompileException()
 {
     var source = "'unclosed string";
     var compiler = new CoffeeScriptCompiler();
     var file = new Mock<IFile>();
     file.SetupGet(f => f.FullPath)
         .Returns("test.coffee");
     var exception = Assert.Throws<CoffeeScriptCompileException>(delegate
     {
         compiler.Compile(source, file.Object);
     });
     exception.SourcePath.ShouldEqual("test.coffee");
 }
Exemplo n.º 11
0
        public CompileResults Compile(string inPath, string outPath)
        {
            CoffeeScriptCompiler compiler = new CoffeeScriptCompiler(new SassAndCoffee.Core.InstanceProvider <IJavaScriptRuntime>(() => new IEJavaScriptRuntime()));

            using (StreamReader sr = new StreamReader(inPath))
            {
                string content = sr.ReadToEnd();
                string output  = compiler.Compile(content);
                using (StreamWriter sw = new StreamWriter(outPath))
                {
                    sw.WriteLine(OrangeBits.GetHeader(inPath));
                    sw.Write(output);
                }
            }
            return(null);
        }
        public void CoffeeScriptFailTest()
        {
            var input = "@#)$(@#)(@#_$)(@_)@ !!@_@@@ window.alert \"foo\" if 3>2 else if else if";
            var fixture = new CoffeeScriptCompiler();

            bool shouldDie = true;

            try {
                var result = fixture.Compile(input);
                Console.WriteLine(result);
            } catch(Exception ex) {
                Console.WriteLine("Ex: " + ex.Message);
                shouldDie = false;
            }

            Assert.False(shouldDie);
        }
Exemplo n.º 13
0
        public void Can_Compile_CoffeeScript()
        {
            // Arrange
            var runtime = new SassAndCoffeeRuntime();
            var compiler = new CoffeeScriptCompiler(runtime);
            var reference = new Reference
                {
                    Extension = ".coffee",
                    Content = "t = 4"
                };
            var result = "var t;\n\nt = 4;\n";

            // Act
            compiler.Compile(ref reference);

            // Assert
            reference.Extension.ShouldBe(".js");
            reference.Content.ShouldBe(result);
        }
Exemplo n.º 14
0
        public void Can_Compile_CoffeeScript_WithoutBare()
        {
            // Arrange
            var runtime = new SassAndCoffeeRuntime();
            var compiler = new CoffeeScriptCompiler(runtime);
            compiler.Bare = false;
            var reference = new Reference
            {
                Extension = ".coffee",
                Content = "t = 4"
            };
            var result = "(function() {\n  var t;\n\n  t = 4;\n\n}).call(this);\n";

            // Act
            compiler.Compile(ref reference);

            // Assert
            reference.Extension.ShouldBe(".js");
            reference.Content.ShouldBe(result);
        }
Exemplo n.º 15
0
        public void Process(BundleContext context, BundleResponse response)
        {
            var coffee = new CoffeeScriptCompiler(new InstanceProvider <IJavaScriptRuntime>(() => new IEJavaScriptRuntime()));

            response.ContentType = "text/javascript";
            response.Content     = string.Empty;

            foreach (var fileInfo in response.Files)
            {
                if (fileInfo.Extension.Equals(".coffee", StringComparison.Ordinal))
                {
                    var result = coffee.Compile(File.ReadAllText(fileInfo.FullName));

                    response.Content += result;
                }
                else if (fileInfo.Extension.Equals(".js", StringComparison.Ordinal))
                {
                    response.Content += File.ReadAllText(fileInfo.FullName);
                }
            }
        }
        private void InnerTranslate(IAsset asset, CoffeeScriptCompiler coffeeScriptCompiler)
        {
            string newContent;
            string assetUrl = asset.Url;

            try
            {
                newContent = coffeeScriptCompiler.Compile(asset.Content, assetUrl);
            }
            catch (CoffeeScriptCompilationException e)
            {
                throw new AssetTranslationException(
                          string.Format(CoreStrings.Translators_TranslationSyntaxError,
                                        INPUT_CODE_TYPE, OUTPUT_CODE_TYPE, assetUrl, e.Message));
            }
            catch (Exception e)
            {
                throw new AssetTranslationException(
                          string.Format(CoreStrings.Translators_TranslationFailed,
                                        INPUT_CODE_TYPE, OUTPUT_CODE_TYPE, assetUrl, e.Message));
            }

            asset.Content = newContent;
        }
		private void InnerTranslate(IAsset asset, CoffeeScriptCompiler coffeeScriptCompiler)
		{
			string newContent;
			string assetVirtualPath = asset.VirtualPath;
			bool isLiterate = (asset.AssetTypeCode == Constants.AssetTypeCode.LiterateCoffeeScript);
			CompilationOptions options = CreateCompilationOptions(isLiterate);

			try
			{
				newContent = coffeeScriptCompiler.Compile(asset.Content, assetVirtualPath, options);
			}
			catch (CoffeeScriptCompilingException e)
			{
				throw new AssetTranslationException(
					string.Format(CoreStrings.Translators_TranslationSyntaxError,
						INPUT_CODE_TYPE, OUTPUT_CODE_TYPE, assetVirtualPath, e.Message));
			}
			catch (Exception e)
			{
				throw new AssetTranslationException(
					string.Format(CoreStrings.Translators_TranslationFailed,
						INPUT_CODE_TYPE, OUTPUT_CODE_TYPE, assetVirtualPath, e.Message));
			}

			asset.Content = newContent;
		}
Exemplo n.º 18
0
        public string GetOutput(string input)
        {
            var compiler = new CoffeeScriptCompiler(new InstanceProvider <IJavaScriptRuntime>(() => new IEJavaScriptRuntime()));

            return(compiler.Compile(input));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Transforms the content of the given string.
        /// </summary>
        /// <param name="input">The input string to transform.</param>
        /// <param name="path">The path to the given input string to transform.</param>
        /// <param name="cruncher">The cruncher that is running the transform.</param>
        /// <returns>The transformed string.</returns>
        public string Transform(string input, string path, CruncherBase cruncher)
        {
            CoffeeScriptCompiler coffeeScriptCompiler = new CoffeeScriptCompiler();

            return(coffeeScriptCompiler.Compile(input));
        }
Exemplo n.º 20
0
 public string Build(string content)
 {
     return(_compiler.Compile(content));
 }
Exemplo n.º 21
0
        public string Process(string filePath, string content)
        {
            var compiler = new CoffeeScriptCompiler();

            return(compiler.Compile(content));
        }
Exemplo n.º 22
0
        public void meepmeep()
        {
            var compiler = new CoffeeScriptCompiler(new InstanceProvider <IJavaScriptRuntime>(() => new IEJavaScriptRuntime()));

            Assert.Pass(compiler.Compile("smoke = (x) -> x * x"));
        }