[DEVELOPMENT ENVIRONMENT]

* BUG: Better detection of regular expressions when compressing a javascript file.

git-svn-id: svn://localhost/gambas/trunk@8141 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
Benoît Minisini 2017-05-30 13:22:52 +00:00
parent 3a87a5e4bb
commit a7b8aad5d3
3 changed files with 18 additions and 4 deletions

View file

@ -31,7 +31,7 @@ Component=gb.util
Description="Integrated Development Environment for Gambas" Description="Integrated Development Environment for Gambas"
Authors="Benoît Minisini\nFabien Bodard\nCharlie Reinl\nJosé Luis Redrejo\nRobert Rowe\nTobias Boege" Authors="Benoît Minisini\nFabien Bodard\nCharlie Reinl\nJosé Luis Redrejo\nRobert Rowe\nTobias Boege"
Arguments=[["~/AVT_Edith-Piaf_1740.jpeg"]] Arguments=[["~/AVT_Edith-Piaf_1740.jpeg"]]
CurrentArgument=1 CurrentArgument=0
TabSize=2 TabSize=2
Translate=1 Translate=1
Language=en Language=en

View file

@ -898,7 +898,7 @@ Public Sub Compress() As Boolean
CompressMessage = "<b>" & Subst(("The file has been compressed from &1 to &2 bytes (&3)."), Str(iLen), Str(Len(sText)), Format(fGain, "#.##%")) & "</b> " & ("Original file has been saved in the <b>Project</b> folder.") CompressMessage = "<b>" & Subst(("The file has been compressed from &1 to &2 bytes (&3)."), Str(iLen), Str(Len(sText)), Format(fGain, "#.##%")) & "</b> " & ("Original file has been saved in the <b>Project</b> folder.")
Endif Endif
Catch Catch
Dec Application.Busy Dec Application.Busy
CompressMessage = "<b>" & ("Unable to compress file.") & "</b><p>" & Error.Text CompressMessage = "<b>" & ("Unable to compress file.") & "</b><p>" & Error.Text

View file

@ -7,6 +7,7 @@ Private Const SUBST_CAR As String = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP
Private $aExt As String[] = ["js", "css", "html"] Private $aExt As String[] = ["js", "css", "html"]
Private $cKeyword As Collection Private $cKeyword As Collection
Private $cKeywordRegexp As Collection
Private $cSubst As Collection Private $cSubst As Collection
Private $cIdent As Collection Private $cIdent As Collection
Private $iSubst As Integer Private $iSubst As Integer
@ -44,6 +45,11 @@ Private Sub InitJavascriptKeywords()
$cKeyword[sStr] = 1 $cKeyword[sStr] = 1
Next Next
$cKeywordRegexp = New Collection
For Each sStr In ["break", "case", "continue", "delete", "do", "else", "finally", "in", "instanceof", "return", "throw", "try", "typeof", "void"]
$cKeywordRegexp[sStr] = True
Next
End End
Private Sub SubstIdent(sIdent As String) Private Sub SubstIdent(sIdent As String)
@ -96,6 +102,7 @@ Public Sub Javascript(sText As String) As String
Dim bKeyword As Boolean Dim bKeyword As Boolean
Dim iPosMem As Integer Dim iPosMem As Integer
Dim bRegExp As Boolean Dim bRegExp As Boolean
Dim sLastKeyword As String
If Not $cKeyword Then InitJavascriptKeywords If Not $cKeyword Then InitJavascriptKeywords
@ -251,6 +258,7 @@ Public Sub Javascript(sText As String) As String
sIdent &= sCar sIdent &= sCar
Continue Continue
Else Else
sLastKeyword = ""
If Len(sIdent) >= 2 If Len(sIdent) >= 2
bKeyword = $cKeyword.Exist(sIdent) bKeyword = $cKeyword.Exist(sIdent)
If Not IsDigit(Left(sIdent)) And If Not bKeyword Then If Not IsDigit(Left(sIdent)) And If Not bKeyword Then
@ -279,6 +287,7 @@ Public Sub Javascript(sText As String) As String
Else If sIdent = "var" Then Else If sIdent = "var" Then
bVar = True bVar = True
Endif Endif
sLastKeyword = sIdent
Endif Endif
Endif Endif
@ -304,8 +313,13 @@ Public Sub Javascript(sText As String) As String
Endif Endif
If Right(sRes) = "\n" Then sRes = Left(sRes, -1) If Right(sRes) = "\n" Then sRes = Left(sRes, -1)
Else If sCar = "/" Then Else If sCar = "/" Then
If sCar2 <> "/ " Then If iPos > 1 Then
bRegExp = True sCar2 = Right(RTrim(Left(sText, iPos - 1)))
If InStr("+-*/.,!%&(:;<=>?[^{|}~", sCar2) Then
bRegExp = True
Else If sLastKeyword And If $cKeywordRegexp.Exist(sLastKeyword) Then
bRegExp = True
Endif
Endif Endif
Else If InStr(" \t\n", sCar) Then Else If InStr(" \t\n", sCar) Then