Skip to content

The method 'allow-cache'() should be a valid syntax #421

@doggy8088

Description

@doggy8088

Describe the bug

Here is the sample code:

class Test {
  'allow-cache'() {
  }
}

The minifiedJs.Errors will produce Expected identifier: 'allow-cache' error. This should be a valid syntax in JS.

To Reproduce

static void Main(string[] args)
{
	// Path to the input JavaScript file
	string inputFilePath = @"G:\test.js";
	// Path to the output minified JavaScript file
	string outputFilePath = @"G:\test.min.js";

	try
	{
		// Read the content of the JavaScript file
		string jsContent = File.ReadAllText(inputFilePath);

		// Minify the JavaScript content
		UglifyResult minifiedJs = Uglify.Js(jsContent, new CodeSettings()
		{
			IgnoreAllErrors = false,
			//EvalTreatment = EvalTreatment.MakeImmediateSafe,
			//PreserveImportantComments = false,
			//TermSemicolons = true,
			MinifyCode = false,
			PreserveFunctionNames = true,
			//LocalRenaming = LocalRenaming.CrunchAll,
		});

		// Check for errors
		if (minifiedJs.HasErrors)
		{
			Console.WriteLine("Errors occurred during minification:");
			foreach (var error in minifiedJs.Errors)
			{
				Console.WriteLine(error.Message);
			}
			File.WriteAllText(outputFilePath, minifiedJs.Code);
		}
		else
		{
			// Write the minified content to the output file
			File.WriteAllText(outputFilePath, minifiedJs.Code);
			Console.WriteLine("JavaScript file minified successfully.");
		}
	}
	catch (Exception ex)
	{
		Console.WriteLine($"An error occurred: {ex.Message}");
	}
}

Minified output or stack trace

class Test{'allow-cache'(){}}

Excepted output code

It should not produce error. It's a valid syntax.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions