Bug 244018

Summary: 'a\n' is considered as a variable
Product: WebKit Reporter: 845043157
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: karlcow, saam, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: Safari 15   
Hardware: All   
OS: All   

Description 845043157 2022-08-16 20:22:34 PDT
Run the program:
var a=1;
a
();

JSC:
TypeError:a
 is not a function

V8 & SpiderMonkey:
TypeError:a is not a function

In the error message,'a/n' is output as the variable name but the really variable name is 'a'.I think it may be a bug.
Comment 1 Karl Dubost 2022-08-16 21:19:46 PDT
Safari, Firefox and Chrome return the same error message.
Comment 2 Karl Dubost 2022-08-16 21:56:46 PDT
but indeed Firefox and Chrome normalizes the output to avoid the return.
Comment 3 Karl Dubost 2022-08-16 21:59:24 PDT
Full Safari output

```
TypeError: a
 is not a function. (In 'a
()', 'a
' is 1)
```

I wonder if it would be better to actually shows the output as:

```
TypeError: a\n is not a function. (In 'a\n()', 'a\n' is 1)
```
Comment 4 845043157 2022-08-18 01:27:59 PDT
'\n' is illegal in variable name and function name.'var a\nb=1' will throw a SyntaxError.So print 'TypeError: a\n is not a function.' may be not a good idea.It regard 'a\n' as a variable name.

But '\n' is meaningless in the end of variable name and function name and will be ignored.

If running the following program:
var a
=1;
print(a);
print(a
);
a=2;
print(a);
print(a
);

It output:
1
1
2
2

So during compilation,'\n' in the end of variable name and function name will be ignored.The '\n' of variable name 'a\n' will be ignored and 'a\n' is regarded as 'a'.

I think 'TypeError:a is not a function' is better.
Comment 5 Karl Dubost 2022-08-18 01:57:45 PDT
Yes agreed. 
But how do we help the developer to discover the error. :) That's where I was coming from.
Comment 6 845043157 2022-08-18 03:58:19 PDT
All I know is that I can report the bug in this website.Isn't it the bug tracking system for JSC?
Comment 7 Radar WebKit Bug Importer 2022-08-23 20:23:18 PDT
<rdar://problem/99064631>