Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CodeMirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moritz Aurel Pascal Schubotz
CodeMirror
Commits
b42563ca
Commit
b42563ca
authored
9 years ago
by
Marijn Haverbeke
Browse files
Options
Downloads
Patches
Plain Diff
[jsx mode] Support JS comments
Issue #3745
parent
b3f94870
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mode/jsx/jsx.js
+27
-16
27 additions, 16 deletions
mode/jsx/jsx.js
mode/jsx/test.js
+9
-0
9 additions, 0 deletions
mode/jsx/test.js
with
36 additions
and
16 deletions
mode/jsx/jsx.js
+
27
−
16
View file @
b42563ca
...
...
@@ -11,11 +11,15 @@
})(
function
(
CodeMirror
)
{
"
use strict
"
function
Context
(
state
,
mode
,
depth
,
prev
)
{
this
.
state
=
state
;
this
.
mode
=
mode
;
this
.
depth
=
depth
;
this
.
prev
=
prev
}
function
copyContext
(
context
)
{
return
{
state
:
CodeMirror
.
copyState
(
context
.
mode
,
context
.
state
),
mode
:
context
.
mode
,
depth
:
context
.
depth
,
prev
:
context
.
prev
&&
copyContext
(
context
.
prev
)
}
return
new
Context
(
CodeMirror
.
copyState
(
context
.
mode
,
context
.
state
),
context
.
mode
,
context
.
depth
,
context
.
prev
&&
copyContext
(
context
.
prev
)
)
}
CodeMirror
.
defineMode
(
"
jsx
"
,
function
(
config
)
{
...
...
@@ -24,7 +28,7 @@
return
{
startState
:
function
()
{
return
{
context
:
{
state
:
CodeMirror
.
startState
(
jsMode
),
mode
:
jsMode
}
}
return
{
context
:
new
Context
(
CodeMirror
.
startState
(
jsMode
),
jsMode
)
}
},
copyState
:
function
(
state
)
{
...
...
@@ -34,27 +38,34 @@
token
:
function
(
stream
,
state
)
{
var
cx
=
state
.
context
if
(
cx
.
mode
==
xmlMode
)
{
if
(
stream
.
peek
()
==
"
{
"
)
{
if
(
cx
.
depth
)
{
// Inside a JS /* */ comment
if
(
stream
.
match
(
/^.*
?\*\/
/
))
cx
.
depth
=
0
else
stream
.
skipToEnd
()
return
"
comment
"
}
else
if
(
stream
.
peek
()
==
"
{
"
)
{
xmlMode
.
skipAttribute
(
cx
.
state
)
state
.
context
=
{
state
:
CodeMirror
.
startState
(
jsMode
,
xmlMode
.
indent
(
cx
.
state
,
""
)),
mode
:
jsMode
,
depth
:
1
,
prev
:
state
.
context
}
state
.
context
=
new
Context
(
CodeMirror
.
startState
(
jsMode
,
xmlMode
.
indent
(
cx
.
state
,
""
)),
jsMode
,
1
,
state
.
context
)
return
jsMode
.
token
(
stream
,
state
.
context
.
state
)
}
else
if
(
stream
.
match
(
"
//
"
))
{
stream
.
skipToEnd
()
return
"
comment
"
}
else
if
(
stream
.
match
(
"
/*
"
))
{
cx
.
depth
=
1
return
this
.
token
(
stream
,
state
)
}
else
{
// FIXME skip attribute
var
style
=
xmlMode
.
token
(
stream
,
cx
.
state
),
cur
,
brace
var
style
=
xmlMode
.
token
(
stream
,
cx
.
state
),
cur
,
stop
if
(
/
\b
tag
\b
/
.
test
(
style
)
&&
!
cx
.
state
.
context
&&
/^
\/?
>$/
.
test
(
stream
.
current
()))
state
.
context
=
state
.
context
.
prev
else
if
(
!
style
&&
(
brace
=
(
cur
=
stream
.
current
()).
indexOf
(
"
{
"
))
>
-
1
)
stream
.
backUp
(
cur
.
length
-
brace
)
else
if
(
!
style
&&
(
stop
=
(
cur
=
stream
.
current
()).
search
(
/
\{
|
\/[
*
\/]
/
))
>
-
1
)
stream
.
backUp
(
cur
.
length
-
stop
)
return
style
}
}
else
{
// jsMode
if
(
stream
.
peek
()
==
"
<
"
&&
jsMode
.
expressionAllowed
(
stream
,
cx
.
state
))
{
jsMode
.
skipExpression
(
cx
.
state
)
state
.
context
=
{
state
:
CodeMirror
.
startState
(
xmlMode
,
jsMode
.
indent
(
cx
.
state
,
""
)),
mode
:
xmlMode
,
prev
:
state
.
context
}
state
.
context
=
new
Context
(
CodeMirror
.
startState
(
xmlMode
,
jsMode
.
indent
(
cx
.
state
,
""
)),
xmlMode
,
0
,
state
.
context
)
return
xmlMode
.
token
(
stream
,
state
.
context
.
state
)
}
else
{
var
style
=
jsMode
.
token
(
stream
,
cx
.
state
)
...
...
This diff is collapsed.
Click to expand it.
mode/jsx/test.js
+
9
−
0
View file @
b42563ca
...
...
@@ -32,4 +32,13 @@
MT
(
"
preserve_js_context
"
,
"
[variable x] [operator =] [string-2 `quasi${][bracket&tag <][tag foo][bracket&tag />][string-2 }quoted`]
"
)
MT
(
"
line_comment
"
,
"
([bracket&tag <][tag foo][bracket&tag >] [comment // hello]
"
,
"
[bracket&tag </][tag foo][bracket&tag >][operator ++])
"
)
MT
(
"
block_comment
"
,
"
([bracket&tag <][tag foo][bracket&tag >] [comment /* hello]
"
,
"
[comment line 2]
"
,
"
[comment line 3 */] [bracket&tag </][tag foo][bracket&tag >][operator ++])
"
)
})()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment